【发布时间】:2013-07-15 13:58:35
【问题描述】:
我有一个类 InitApp
@Component
public class InitApp implements ServletContextListener {
@Autowired
ConfigrationService weatherConfService;
/** Creates a new instance of InitApp */
public InitApp() {
}
public void contextInitialized(ServletContextEvent servletContextEvent) {
System.out.println(weatherConfService);
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
和 web.xml 中的监听器:
<listener>
<listener-class>com.web.Utils.InitApp</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
confService 打印 --> null 什么问题?
【问题讨论】:
-
您应该在 xml Spring 配置中定义
ConfigurationService,正如 Nambari 指出的那样,或者您应该将component-scan放在包含ConfigurationService的包上,并使用@Component或@Service
标签: java spring spring-mvc