将我的应用程序从(spring-webmvc-3.0.5和tiles 2.0)迁移到(spring-webmvc-3.2.8 tiles 3.0)时获取bean创建异常

时间:2014-09-30 10:16:34

标签: java spring spring-mvc tiles-3

迁移时出现以下错误...请提出解决方案

   SEVERE: Servlet.service() for servlet [default] in context with path [/destinations] threw exception [Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homePageTemplate': Invocation of init method failed; nested exception is java.lang.NullPointerException] with root cause
        12:52:16.905 | java.lang.NullPointerException
        12:52:16.907 |  at org.apache.tiles.access.TilesAccess.getContainer(TilesAccess.java:124)
        12:52:16.910 |  at org.apache.tiles.access.TilesAccess.getContainer(TilesAccess.java:107)
        12:52:16.913 |  at org.springframework.web.servlet.view.tiles3.TilesView.afterPropertiesSet(TilesView.java:94)
        12:52:16.916 |  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
        12:52:16.919 |  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
        12:52:16.922 |  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:388)
        12:52:16.925 |  at org.springframework.web.servlet.view.UrlBasedViewResolver.applyLifecycleMethods(UrlBasedViewResolver.java:442)
        12:52:16.927 |  at org.springframework.web.servlet.view.UrlBasedViewResolver.loadView(UrlBasedViewResolver.java:437)
        12:52:16.930 |  at org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:241)
        12:52:16.933 |  at org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:401)
        12:52:16.935 |  at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:153)
        12:52:16.938 |  at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1239)
        12:52:16.941 |  at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1188)
        12:52:16.943 |  at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
        12:52:16.983 |  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
        12:52:16.984 |  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
        12:52:16.987 |  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
        12:52:16.989 |  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
        12:52:16.991 |  at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
        12:52:16.994 |  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
        12:52:16.997 |  at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        12:52:17.001 |  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        12:52:17.004 |  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        12:52:17.006 |  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        12:52:17.009 |  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        12:52:17.011 |  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        12:52:17.014 |  at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
        12:52:17.017 |  at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
        12:52:17.020 |  at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
        12:52:17.022 |  at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
        12:52:17.025 |  at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
        12:52:17.028 |  at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
        12:52:17.031 |  at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        12:52:17.035 |  at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        12:52:17.038 |  at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
        12:52:17.042 |  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        12:52:17.045 |  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        12:52:17.048 |  at uk.co.portaltech.tui.framework.hybris.TUISiteFilter.doFilterInternal(TUISiteFilter.java:65)
        12:52:17.051 |  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        12:52:17.054 |  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        12:52:17.057 |  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        12:52:17.059 |  at uk.co.portaltech.tui.framework.hybris.CMSSiteFilter.doFilterInternal(CMSSiteFilter.java:129)
        12:52:17.062 |  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        12:52:17.065 |  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        12:52:17.068 |  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        12:52:17.070 |  at de.hybris.platform.util.RootRequestFilter.doFilter(RootRequestFilter.java:873)
        12:52:17.073 |  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        12:52:17.075 |  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        12:52:17.078 |  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        12:52:17.081 |  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        12:52:17.084 |  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        12:52:17.116 |  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        12:52:17.117 |  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        12:52:17.121 |  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        12:52:17.124 |  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        12:52:17.127 |  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
        12:52:17.131 |  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
        12:52:17.132 |  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        12:52:17.139 |  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        12:52:17.142 |  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        12:52:17.145 |  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        12:52:17.149 |  at java.lang.Thread.run(Unknown Source)

以下是我的图块中的条目

<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
        "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

我们在mvc-servlet.xml中有这些条目

 <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
             <value>/WEB-INF/defs/tiles-config.xml</value>
             </list>
        </property>
    </bean>

    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
        <property name="order" value="0" />
    </bean>

如果我们使用tiles2而不是tiles3,我们就会得到

javax.servlet.ServletException: Tiles container is not initialized. Have you added a TilesConfigurer to your web application context?
非常感谢

2 个答案:

答案 0 :(得分:0)

我认为你应该把tiles-config.xml放在/ WEB-INF / defs /目录中并把正确的内容放到它上面

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="index" template="/WEB-INF/jsp/templates/templateuser.jsp">
<put-attribute name="content" value="/WEB-INF/jsp/index.jsp" />
</definition>
</tiles-definitions>

答案 1 :(得分:0)

确保Spring Boot初始化您的bean定义 运行时的mvc-servlet.xml配置文件。当tilesConfigurer未实例化时,通常会出现此问题。

出现这种情况的原因有很多:

  • Spring Boot无法加载xml配置(mvc-servlet.xml)
  • tilesConfigurer bean标记为抽象bean
  • tilesConfigurer.definitions属性中的错误路径