我想通过JPA @Entity
自动添加一个通过@Component/@Resource/@Configurable
注释的类,所以我添加了Spring的@Component
@Entity
@Table
public class Employee{
@Autowired
TestService testService;
...
}
注释,但它不允许我自动加载该类。
是否需要其他注释?。
示例是:
TestService
使用@Service
注释班级$("#cols").on('mouseenter',cols,function(){
cols.resizable({
maxHeight: 20,
minHeight: 20,
distance: 5,
handles: 'e',
start: function() {
console.log("I've started!");
},
stop: function() {
console.log("I've stopped!");
}
});
});
。
答案 0 :(得分:1)
您可以轻松地执行此操作,创建构造函数并将注入的Service作为参数传递:
@Component
@Entity
@Table
public class Employee{
Employee(TestService testService){
//Do some work
}
...
}
现在调用者类..
@Service
public class CallerClass{
@Autowired
TestService testService;
Employee employee =new Employee(testService);
}
答案 1 :(得分:-1)
您需要使用@Configurable
@Entity
@Table
@Configurable
public class Employee{
@Autowired
TestService testService;
...
}