小编gka*_*mal的帖子

error引用的类型不是注释类型:

我有以下看点

@Around("execution(public * (@DisabledForBlockedAccounts *).*(..))" + " && @annotation(denyForTeam)")
public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny) throws Throwable
{
    Account account = (Account) pjp.getArgs()[0];
    Account selectedAccount = (Account) pjp.getArgs()[1];

    if (ArrayUtils.contains(deny.value(), account.getRole()))
    {

        if (account.getType().equals(Type.CHEF) && !selectedAccount.getType().equals(Type.CHEF))
        {
            throw new IllegalAccessException("");
        }
    }
    return pjp.proceed();
}
Run Code Online (Sandbox Code Playgroud)

和这个注释:

@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface DenyForTeam
{

Role[] value();

}
Run Code Online (Sandbox Code Playgroud)

我得到错误:错误引用的类型不是注释类型:denyForTeam

为什么DenyForTeam没有注释?它标有@interface

aop spring spring-aop

12
推荐指数
2
解决办法
2万
查看次数

何时是一个精确调用的@ModelAttribute注释方法?

以下是一个简单的Spring表单控制器来处理"添加项目"用户请求:

@Controller
@RequestMapping("/addItem.htm")
public class AddItemFormController {

    @Autowired
    ItemService itemService;

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(ModelMap model) {
        return "addItem";
    }

    @ModelAttribute("item")
    public Item setupItem() {
        Item item = new Item();
        return item;
    }

    @RequestMapping(method = RequestMethod.POST)
    protected String addItem(@ModelAttribute("item") Item item) {
        itemService.addItem(item);
        return "itemAdded";
    }

}
Run Code Online (Sandbox Code Playgroud)

我在某处读到: (...) the @ModelAttribute is also pulling double duty by populating the model with a new instance of Item before the form is displayed and then pulling the Item from the model …

java data-binding spring spring-mvc modelattribute

5
推荐指数
1
解决办法
2376
查看次数

将Session对象注入DAO bean而不是Session Factory?

在我们的应用程序中,我们使用Spring和Hibernate.

在所有DAO类中,我们自动连接SessionFactory,每个DAO方法都调用getCurrentSession()方法.

问题我有为什么不在原型范围中注入Session对象而不是SessionFactory对象?这将节省我们对getCurrentSession的调用.

我认为第一种方法是正确的,但寻找第二种方法会抛出错误或可能性能不佳的具体情况?

spring hibernate

5
推荐指数
1
解决办法
1086
查看次数

Spring的上下文命名空间如何工作?

例如,如果我在application-context.xml中声明:

<context:annotation-config/>
Run Code Online (Sandbox Code Playgroud)

我从官方文件中读到:

在隐式注册后处理器包括AutowiredAnnotationBeanPostProcessor,CommonAnnotationBeanPostProcessor会,PersistenceAnnotationBeanPostProcessor,以及上述RequiredAnnotationBeanPostProcessor.

但我想知道Spring是如何工作的,我认为这个1-liner被转换为文档中提到的后处理器的几个bean定义.

但是,我的问题是,哪个Spring组件/类实现了"从1-liner到多个bean定义的转换"功能?

java spring xml-namespaces post-processing applicationcontext

4
推荐指数
1
解决办法
2805
查看次数

使用spring数据JPA映射和获取具有复合键的实体

我有Spring MVC和Data JPA.我正在尝试做我有的映射表.结构如下:

Device
--------------
PK deviceId
   deviceName


Setting
--------------
PK deviceId
PK packageName
PK name
   value
Run Code Online (Sandbox Code Playgroud)

我有这些表的类:

@Entity
public class DeviceSetting implements Serializable {
    @EmbeddedId
    private String deviceId
    private String deviceName;

    @ManyToOne
    @JoinColumn(name="deviceId", referencedColumnName="deviceId", insertable=false, updatable=false)
    private Device device;

    //Setters and Getters
}

@Embeddable
public class DeviceSettingPk implements Serializable {

    private String deviceId;
    private String packageName;
    private String name;

    public DeviceSettingPk(){}
    public DeviceSettingPk(String deviceId, String packageName, String name) {
        super();
        this.deviceId = deviceId;
        this.packageName = packageName;
        this.name = name; …
Run Code Online (Sandbox Code Playgroud)

jpa spring-data-jpa

2
推荐指数
1
解决办法
2万
查看次数