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中的所有规则:
有什么想法吗?
答案 0 :(得分:2)
如果没有拼写错误,我相信正确的是
@ComponentScan(basePackages = { "myproject.web"})
因为AppComponentFactory
位于myproject.web.factory
包中。