A类:
package myproject.web.factory.components;
@Component
public class AppComponentFactory{
}
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
}
}
配置XML:
<context:component-scan base-package="myproject.spring" />
WebConfig.java:
package myproject.spring.config;
@Configuration
@ComponentScan(basePackages = { "myproject.web.components"})
public class WebConfig {
我遵守了http://docs.oracle.com/javaee/5/api/javax/annotation/PostConstruct.html中的所有规则:
有任何想法吗?
最佳答案
如果没有错字,我相信正确的是
@ComponentScan(basePackages = { "myproject.web"})
因为
AppComponentFactory
在myproject.web.factory
包中。关于java - Spring :@PostConstruct不被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13918988/