[英]Spring: @PostConstruct is not called
Class A: A类:
package myproject.web.factory.components;
@Component
public class AppComponentFactory{
}
Class B B级
package myproject.web.components;
import myproject.web.factory.components.AppComponentFactory;
@Component
public class AdminTabSheet{
@Autowired
private AppComponentFactory appComponentFactory;
public AdminTabSheet() {
}
@PostConstruct
public void init() {
// does something with appComponentFactory
}
}
Configuration XML: 配置XML:
<context:component-scan base-package="myproject.spring" />
WebConfig.java: WebConfig.java:
package myproject.spring.config;
@Configuration
@ComponentScan(basePackages = { "myproject.web.components"})
public class WebConfig {
I have followed all the rules in http://docs.oracle.com/javaee/5/api/javax/annotation/PostConstruct.html : 我遵守了http://docs.oracle.com/javaee/5/api/javax/annotation/PostConstruct.html中的所有规则:
Any ideas? 有任何想法吗?
If there was no typo, I believe the correct would be 如果没有错字,我相信正确的是
@ComponentScan(basePackages = { "myproject.web"})
since AppComponentFactory
is in myproject.web.factory
package. 因为
AppComponentFactory
位于myproject.web.factory
包中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.