Cant find config files in Jetty + Spring + Tiles deployement

好久不见. 提交于 2019-12-13 04:21:37

问题


I have a Spring + Tiles project which is working fine and now I planned to move it into Jetty instead of deploying on Tomcat. So configured jetty server to use { DispatcherServlet} and set my setContextConfigLocation("classpath:spring-application-context.xml"). In my application context xml I have tiles configured and my tiles.xml file is in WEB-INF directory, but during initialization my application never finds it, doesnt matter it is in classpath or not, it cant find it.

My deployment directory structure

|- my_app.jar
|- WEB-INF
   |- tiles.xml
   |- views
      | - jsps's here

my application context xml

<context:component-scan base-package="com.jetty.spring"/>

<mvc:annotation-driven/>

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</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>

Jetty server code

Server server = new Server(8080);
Context context = new Context(server, "/", Context.SESSIONS);

DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation("classpath:spring-application-context.xml");

ServletHolder servletHolder = new ServletHolder(dispatcherServlet);
context.addServlet(servletHolder, "/*");

server.start();
server.join();

any help ?


回答1:


Use Jetty plugin for Maven for running your application with a simple configuration and without coding anything. For example:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.26</version>
    <configuration>
        <webAppConfig>
            <contextPath>/</contextPath>
        </webAppConfig>
    </configuration>
</plugin>

Then, just use mvn jetty:run to run your application.



来源:https://stackoverflow.com/questions/9896694/cant-find-config-files-in-jetty-spring-tiles-deployement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!