首页 新闻 会员 周边

为什么InitializingBean不执行

0
悬赏园豆:10 [已解决问题] 解决于 2016-10-19 10:49

我想通过实现InitializingBean接口来初始化一些数据。

InitDataListener类:
复制代码
public class InitDataListener implements InitializingBean, ServletContextAware {
    
    public void afterPropertiesSet() throws Exception {
        System.out.println("init:afterPropertiesSet()");
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        System.out.println("init:setServletContext()");
    }
}
复制代码

springmvc中以加入配置:

<bean class="cn.edu.svtcc.microcourse.listener.InitDataListener"> </bean>

web.xml配置

    <!-- 配置springmvc -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- /配置springmvc -->

 

启动项目时没有任何反应

Ctony的主页 Ctony | 初学一级 | 园豆:15
提问于:2016-07-20 12:03
< >
分享
最佳答案
0

InitDataListener  加个@service注释看看

收获园豆:10
CyrusLeo | 菜鸟二级 |园豆:220 | 2016-07-23 15:27
其他回答(1)
0

启动时首先加载web.xml,,,web.xml你有没有配置  引用这个类所在的springmvc.xml

弦断有谁听 | 园豆:20 (初学一级) | 2016-07-20 12:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册