相关疑难解决方法(0)

我应该在哪里放置@Transactional注释:在接口定义或实现类?

代码中标题的问题:

@Transactional (readonly = true)
public interface FooService {
   void doSmth ();
}


public class FooServiceImpl implements FooService {
   ...
}
Run Code Online (Sandbox Code Playgroud)

VS

public interface FooService {
   void doSmth ();
}

@Transactional (readonly = true)
public class FooServiceImpl implements FooService {
   ...
}
Run Code Online (Sandbox Code Playgroud)

java spring annotations coding-style

82
推荐指数
3
解决办法
3万
查看次数

Spring Data 删除功能不删除记录

我有以下简单的应用程序

Users 实体

@Entity
public class Users implements Serializable {

   @Id
   @GeneratedValue
   private long id;

   private String name;

   @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
   private Set<UserRoleUser> userRoleUser;

   // GETTERS AND SETTERS
}
Run Code Online (Sandbox Code Playgroud)

UserRole 实体

@Entity
public class UserRole implements Serializable {

   @Id
   @GeneratedValue
   private long id;

   private String roleName;

   @OneToMany(mappedBy = "userrole", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   private Set<UserRoleUser> userRoleUser;

   // GETTERS AND SETTERS
}
Run Code Online (Sandbox Code Playgroud)

UserRoleUser 多对多解析器类

@Entity
public class UserRoleUser implements Serializable {

   @Id
   @GeneratedValue …
Run Code Online (Sandbox Code Playgroud)

java spring querydsl spring-data-jpa spring-boot

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

Spring Java配置,@ Autowire与构造函数注入,@ Transaction和CGLIB

我们一直在使用@Autowired基于Java的Spring配置并取得了一些成功,但现在我们失去了控制权.每个人都开始在任何地方添加自动连接的依赖项,创建周期和奇怪的错误.

所以我们正在考虑使用构造函数注入和Spring配置的自动装配.

旧:

class Bean {
   @Autowired Foo foo;
}

@Configuration
@Import( FooCfg.class )
class BeanCfg {
   @Bean public Bean bean() { return new Bean(); }
}
Run Code Online (Sandbox Code Playgroud)

新:

class Bean {
   public Bean(Foo foo) {...}
}

@Configuration
class BeanCfg {
   @Autowired FooCfg fooCfg;
   @Bean public Bean bean() { return new Bean(fooCfg.foo()); }
}
Run Code Online (Sandbox Code Playgroud)

这非常有效(并且它驱使人们分割bean而不是创建具有10个以上构造函数参数的怪物).

但是当Bean有一个方法注释时它会失败,@Transactional因为CGLIB然后尝试创建一个失败的代理,因为它找不到无参构造函数.

这是什么解决方案?

spring proxy-classes transactional autowired cglib

3
推荐指数
1
解决办法
5939
查看次数