问题描述:

I'm developing a web application with Spring MVC using Tiles.When I run my app,I encounter HTTP Status 500 - Servlet.init() for servlet appServlet threw exception

Development Environment

 - Spring MVC 3.2.3 Release

- Tiles 2.2.1

tiles-core-2.2.1.jar

tiles-template-2.2.1.jar

tiles-jsp-2.2.1.jar

tiles-servlet-2.2.1.jar

tiles-api-2.2.1.jar

tiles-request-api-1.0.1.jar

File locations

servlet-context.xml

<bean id="viewResolver"

class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">

<property name="viewClass"

value="org.springframework.web.servlet.view.tiles2.TilesView">

</property>

</bean>

<bean id="tilesConfigurer"

class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">

<property name="definitions">

<list>

<value>

WEB-INF/tiles.xml

</value>

</list>

</property>

</bean>

tiles.xml

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

<tiles-definitions>

<definition name="base.definition"

template="/WEB-INF/views/templates/template1/layout.jsp">

<put-attribute name="title" value="" />

<put-attribute name="header" value="/WEB-INF/views/templates/components/header.jsp"/>

<put-attribute name="menu" value="menu"/>

<put-attribute name="body" value="" />

<put-attribute name="footer" value="/WEB-INF/views/templates/components/footer.jsp" />

</definition>

<definition name="menu"

preparer="menuController"

template="/WEB-INF/views/templates/components/menu.jsp">

</definition>

<definition name="secondary.definition"

template="/WEB-INF/views/templates/template2/layout2.jsp" preparer="menuController">

<put-attribute name="title" value="" />

<put-attribute name="header" value="/WEB-INF/views/templates/components/header.jsp"/>

<put-attribute name="body" value="" />

<put-attribute name="footer" value="/WEB-INF/views/templates/components/footer.jsp" />

</definition>

<definition name="anasayfa" extends="base.definition">

<put-attribute name="title" value="Anasayfa" />

<put-attribute name="body" value="/WEB-INF/views/home.jsp" />

</definition>

<definition name="kategori" extends="base.definition">

<put-attribute name="title" value="Kategori" />

<put-attribute name="body" value="/WEB-INF/views/kategori.jsp" />

</definition>

<definition name="kod" extends="base.definition">

<put-attribute name="title" value="Kod" />

<put-attribute name="body" value="/WEB-INF/views/kod.jsp" />

</definition>

<definition name="login" extends="secondary.definition">

<put-attribute name="title" value="Login" />

<put-attribute name="body" value="/WEB-INF/views/login.jsp" />

</definition>

<definition name="kayit" extends="secondary.definition">

<put-attribute name="title" value="Kayit" />

<put-attribute name="body" value="/WEB-INF/views/kayit.jsp" />

</definition>

<definition name="upload" extends="secondary.definition">

<put-attribute name="title" value="Ek" />

<put-attribute name="body" value="/WEB-INF/views/upload.jsp" />

</definition>

<definition name="kullanici" extends="secondary.definition">

<put-attribute name="title" value="Kullanici" />

<put-attribute name="body" value="/WEB-INF/views/kullanici.jsp" />

</definition>

</tiles-definitions>

Stacktrace

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Invocation of init method failed; nested exception is org.apache.tiles.definition.DefinitionsFactoryException: Cannot load definition URLs

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)

at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)

at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)

at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)

at javax.servlet.GenericServlet.init(GenericServlet.java:158)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)

at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:670)

at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

at java.util.concurrent.FutureTask.run(FutureTask.java:166)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

Caused by: org.apache.tiles.definition.DefinitionsFactoryException: Cannot load definition URLs

at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.getSourceURLs(TilesConfigurer.java:428)

at org.apache.tiles.factory.BasicTilesContainerFactory.createLocaleDefinitionDao(BasicTilesContainerFactory.java:298)

at org.apache.tiles.factory.BasicTilesContainerFactory.createDefinitionsFactory(BasicTilesContainerFactory.java:242)

at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.createDefinitionsFactory(TilesConfigurer.java:481)

at org.apache.tiles.factory.BasicTilesContainerFactory.createContainer(BasicTilesContainerFactory.java:104)

at org.apache.tiles.startup.AbstractTilesInitializer.createContainer(AbstractTilesInitializer.java:124)

at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:70)

at org.springframework.web.servlet.view.tiles2.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:339)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)

... 33 more

Caused by: java.io.FileNotFoundException: ServletContext resource [/

WEB-INF/tiles.xml

] cannot be resolved to URL because it does not exist

at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:154)

at org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext.getResources(SpringTilesApplicationContextFactory.java:105)

at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.getSourceURLs(TilesConfigurer.java:423)

... 42 more

Tem 17, 2014 12:18:21 AM org.apache.catalina.core.StandardContext loadOnStartup

SEVERE: Servlet /controller threw load() exception

java.io.FileNotFoundException: ServletContext resource [/

WEB-INF/tiles.xml

] cannot be resolved to URL because it does not exist

at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:154)

at org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext.getResources(SpringTilesApplicationContextFactory.java:105)

at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.getSourceURLs(TilesConfigurer.java:423)

at org.apache.tiles.factory.BasicTilesContainerFactory.createLocaleDefinitionDao(BasicTilesContainerFactory.java:298)

at org.apache.tiles.factory.BasicTilesContainerFactory.createDefinitionsFactory(BasicTilesContainerFactory.java:242)

at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.createDefinitionsFactory(TilesConfigurer.java:481)

at org.apache.tiles.factory.BasicTilesContainerFactory.createContainer(BasicTilesContainerFactory.java:104)

at org.apache.tiles.startup.AbstractTilesInitializer.createContainer(AbstractTilesInitializer.java:124)

at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:70)

at org.springframework.web.servlet.view.tiles2.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:339)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)

at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)

at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)

at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)

at javax.servlet.GenericServlet.init(GenericServlet.java:158)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)

at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:670)

at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

at java.util.concurrent.FutureTask.run(FutureTask.java:166)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

Briefly stack trace I got this exception

java.io.FileNotFoundException: ServletContext resource [/

WEB-INF/tiles.xml

] cannot be resolved to URL because it does not exist

How can I solve this problem?Thanks in advance

网友答案:

Seems like it is unable to find tiles file make sure your path to tiles.xml is correct

This is correct

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

        </property>
    </bean>

Incorrect way

<bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
             \\This may lead to leading space in path
                <value>
                    WEB-INF/tiles.xml
                </value>
            </list>

        </property>
    </bean>
相关阅读:
Top