Spring MVC从应用程序战争文件中分离资产

阿米特

我在tomcat apache服务器上使用java spring和jsp编写了一个简单的Web应用程序,名为“ webdemo”。我的目标是将资产(jsp,图像,css,js)与项目war文件分离,并将它们存储在tomcat的类路径中,该类路径设置为tomact的“ common”文件夹。

webdemo-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>


    <import resource="externalizationContext.xml"/> 

    <mvc:annotation-driven/>

    <context:component-scan base-package="com.mckesson.voucher"/>

    <mvc:resources mapping="/images/**" location="classpath:application-assets/webdemo/images/" />
    <mvc:resources mapping="/scripts/**" location="classpath:application-assets/webdemo/scripts/" />

    <bean id="couponBean" class="com.mckesson.voucher.model.CouponBean" scope="session">
        <aop:scoped-proxy />
    </bean>



    <util:properties id="voucherProperties"
        location="classpath:application-config/webdemo/externalization/webdemo.properties" />
    <util:properties id="voucherEnvProperties"
        location="classpath:application-config/webdemo/logging/loggingTags.properties" />
    <util:properties id="voucherDBEnvProperties"
        location="classpath:application-config/datasource/dataSource.properties" />


<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="classpath:application-assets/webdemo/" />
    <property name="suffix" value=".jsp" />
</bean>


</beans>

web.xml

   <!-- General description of your web application -->
      <display-name>McKesson webdemo</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dbContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>webdemo</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>      
    <servlet-mapping>
        <servlet-name>webdemo</servlet-name>
        <url-pattern>/home.html</url-pattern>
    </servlet-mapping>  
    <servlet-mapping>
        <servlet-name>webdemo</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

      <welcome-file-list>
        <welcome-file>home.html</welcome-file>
    </welcome-file-list>


      <!-- Define the default session timeout for your application,
            in minutes.  From a servlet or JSP page, you can modify
            the timeout for a particular session dynamically by using
            HttpSession.getMaxInactiveInterval(). -->
      <session-config>
            <session-timeout>30</session-timeout><!-- 30 minutes -->
      </session-config>
</web-app>

我们在tomcat上托管了将近300个Web项目,最终目标是将所有资产放置在tomcat的公共文件夹下与每个Web项目相对应的单个位置。

在这里的任何帮助将不胜感激。

javaMoca

这实际上是一个好主意,但您可能会犯错。您需要了解的一件事是您不想分离jsp。保留在春天。您要分隔js,css和图像,因为它们是静态内容。在企业环境中执行此操作的常见方法是在Tomcat服务器之前安装一个Web服务器(例如Apache)。您将静态内容放在Apache服务器上,并配置该服务器以将静态内容传递到浏览器,同时将对动态内容的调用发送到Tomcat并通过Apache服务器进行中继。这样可以减少Tomcat服务器上的负载。您也许可以在一台服务器上完成所有操作,但是我还没有尝试过。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章