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中的所有规则:
- 此注解只能注解一种方法。
- 除 EJB 拦截器外,该方法不得有任何参数
- 方法的返回类型必须为 void。
- 该方法不得抛出已检查的异常。
- 应用 PostConstruct 的方法可以是公共的、受保护的、包私有的或私有的。
- 该方法不能是静态的。
有任何想法吗?