SpringMVC部署步骤

1.导包(可以是用Maven)

2.配置Web.XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>SCUT_M</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
     <!-- 配置监听器 -->  
    <listener>  
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
     <!-- 在项目启动时,加载spring配置文件 -->  
   <context-param>  
       <param-name>contextConfigLocation</param-name>  
       <param-value>
            classpath:application-context.xml
       </param-value>  
   </context-param>  
    <!-- 声明servlet -->
    <servlet>
        <servlet-name>SCUT_M</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
     <!-- 配置servlet映射 -->
    <servlet-mapping>
        <servlet-name>SCUT_M</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

3.配置spring的配置文件
分别是
1)application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
       default-lazy-init="false">
    <!-- 元数据扫描 -->  
     <context:component-scan base-package="com.allimu.*"></context:component-scan>
     <context:annotation-config/>

    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
            </list>
        </property>
    </bean>
    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
          destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClassName}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <!-- 连接的空闲存活时间,当连接空闲时间大于该阀值时,清除该连接 -->
        <property name="idleMaxAge" value="240"/>
        <!-- 每个分区含有的最大连接数 -->
        <property name="maxConnectionsPerPartition" value="100"/>
        <!-- 每个分区含有的最小连接数 -->
        <property name="minConnectionsPerPartition" value="30"/>
        <!-- 分区数量 -->
        <property name="partitionCount" value="3"/>
        <!-- 每次新增连接的数量 -->
        <property name="acquireIncrement" value="5"/>
        <!-- 语句缓存个数 -->
        <property name="statementsCacheSize" value="50"/>
        <!-- 连接池助手线程数量,可设置为0,该参数会降低运行速度,但程序有大量连接时,有助于提升高并发程序的性能 -->
        <property name="releaseHelperThreads" value="3"/>
        <!-- 语句助手线程数,可设置为0,该参数会降低运行速度,但程序有大量的查询语句时,有助于提升高并发程序的性能 -->
        <property name="statementReleaseHelperThreads" value="3"/>
        <!-- 测试连接有效性的间隔时间,单位分钟 -->
        <property name="idleConnectionTestPeriod" value="60"/>
        <!-- 连接测试语句 -->
        <property name="connectionTestStatement" value="select 1 from dual"/>
        <!-- 连接超时时间,单位毫秒 -->
        <property name="connectionTimeout" value="10000"/>
    </bean>


    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>


            </list>
        </property>
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
                <!-- hibernate.dialect=org.hibernate.dialect.OracleDialect -->
                hibernate.show_sql=false
                hibernate.query.substitutions=true 1, false 0
                hibernate.jdbc.fetch_size=100
                hibernate.jdbc.batch_size=200
                hibernate.cache.use_query_cache=false
            </value>
        </property>

    </bean>

    <bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>


    <!-- 支持 @AspectJ -->
    <aop:aspectj-autoproxy/>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="transactionInterceptor"
          class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="transactionManager"/>
        </property>
        <!-- 配置事务属性 -->
        <property name="transactionAttributes">
            <props>
                <prop key="delete*">PROPAGATION_REQUIRED</prop>
                <prop key="add*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>

    <bean id="namingStrategy" class="org.hibernate.cfg.ImprovedNamingStrategy"/>

    <!-- spring hibernate工具类模板 -->
    <bean id="hibernateTemplate"
          class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

</beans>
    2)servlet-context.xml
        需要配置FreeMarker的prefix属性(html路径)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
    default-lazy-init="false">


    <context:component-scan base-package="com.allimu.web,com.allimu.webapps,com.allimu.webservice"></context:component-scan>
    <!--<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/page/"/> <property name="suffix" 
        value=".jsp"/> </bean> --><!-- freemarker的配置 -->

    <bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/" />
        <property name="defaultEncoding" value="UTF-8" />
        <property name="freemarkerSettings">
            <props>
                <prop key="template_update_delay">0</prop>
                <prop key="defaultEncoding">UTF-8</prop>
                <prop key="url_escaping_charset">UTF-8</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="boolean_format">true,false</prop>
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
                <prop key="date_format">yyyy-MM-dd</prop>
                <prop key="time_format">HH:mm:ss</prop>
                <prop key="number_format">0.######</prop>
                <prop key="whitespace_stripping">true</prop>
                <!-- <prop key="classic_compatible">true</prop> -->
            </props>
        </property>
    </bean>
    <!-- FreeMarker视图解析 如返回userinfo。。在这里配置后缀名ftl和视图解析器。。 -->
    <bean id="freemarkerViewResolver"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
        <property name="cache" value="true" />
        <property name="prefix" value="/" />
        <property name="suffix" value=".html" />
        <property name="contentType" value="text/html;charset=UTF-8" />
        <property name="requestContextAttribute" value="request" />
        <property name="exposeRequestAttributes" value="true" />
        <property name="exposeSessionAttributes" value="true" />
        <property name="exposeSpringMacroHelpers" value="true" />
    </bean>


    <bean class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver" />
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize">  
            <value>104857600</value>  
        </property>  
        <property name="maxInMemorySize">  
            <value>4096</value>  
        </property>
    </bean>
    <bean id="viewNameTranslator"
        class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator">
        <property name="stripExtension" value="false" />
    </bean>
    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="cookieName" value="clientlanguage" />
        <property name="cookieMaxAge" value="-1" />
    </bean>
    <bean class="com.allimu.exception.ImuExceptionResolver" />
    <context:annotation-config />


</beans>

4.配置dev/online配置文件

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值