記錄一下第一次配SSM的經過

(Spring+SpringMvc+Mybatis)

學習的博客地址:
http://blog.csdn.net/wrp920227/article/details/54588238
http://blog.csdn.net/gebitan505/article/details/44455235/
在此感謝 wrpys、AndyLizh 大神

1. 使用maven搭建需要引入的jar包

(個人感覺應該是會自動去https://mvnrepository.com/ 下載,由於還是第一配若有錯誤請大神多多包涵,多多指點。)
pom.xml:


    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 

  <modelVersion>4.0.0</modelVersion>  
  <groupId>com.wrpys.ssm</groupId>  
  <artifactId>SSM</artifactId>  
  <packaging>war</packaging>  
  <version>1.0-SNAPSHOT</version>  
  <name>SSM</name>  

  <!-- 編碼 -->  
  <properties>  
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
  </properties>  

  <!--Maven依賴 需要更換可以到http://mvnrepository.com進行查詢-->  
  <dependencies>  

    <!--Spring-->  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-core</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-aop</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-orm</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-web</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-webmvc</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-tx</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-test</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-jdbc</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-mock</artifactId>  
      <version>2.0.8</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-context</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-expression</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  
    <dependency>  
      <groupId>org.springframework</groupId>  
      <artifactId>spring-context-support</artifactId>  
      <version>4.3.5.RELEASE</version>  
    </dependency>  

    <!-- mybatis-spring -->  
    <dependency>  
      <groupId>org.mybatis</groupId>  
      <artifactId>mybatis-spring</artifactId>  
      <version>1.3.1</version>  
    </dependency>  

    <!-- mybatis 出現分頁使用異常,極有可能是版本問題-->  
    <dependency>  
      <groupId>org.mybatis</groupId>  
      <artifactId>mybatis</artifactId>  
      <version>3.2.8</version>  
    </dependency>  
    <!-- mybatis pagehelper -->  
    <dependency>  
      <groupId>com.github.pagehelper</groupId>  
      <artifactId>pagehelper</artifactId>  
      <version>3.7.3</version>  
    </dependency>  
    <dependency>  
      <groupId>com.github.jsqlparser</groupId>  
      <artifactId>jsqlparser</artifactId>  
      <version>0.9.1</version>  
    </dependency>  

    <!--servlet、基本包-->  
    <dependency>  
      <groupId>javax.servlet</groupId>  
      <artifactId>servlet-api</artifactId>  
      <version>3.0-alpha-1</version>  
    </dependency>  
    <dependency>  
      <groupId>javax.servlet</groupId>  
      <artifactId>jstl</artifactId>  
      <version>1.2</version>  
    </dependency>  
    <dependency>  
      <groupId>taglibs</groupId>  
      <artifactId>standard</artifactId>  
      <version>1.1.2</version>  
    </dependency>  
    <dependency>  
      <groupId>org.aspectj</groupId>  
      <artifactId>aspectjrt</artifactId>  
      <version>1.8.10</version>  
    </dependency>  
    <dependency>  
      <groupId>org.aspectj</groupId>  
      <artifactId>aspectjweaver</artifactId>  
      <version>1.8.10</version>  
    </dependency>  
    <dependency>  
      <groupId>commons-lang</groupId>  
      <artifactId>commons-lang</artifactId>  
      <version>2.6</version>  
    </dependency>  
    <dependency>  
      <groupId>dom4j</groupId>  
      <artifactId>dom4j</artifactId>  
      <version>1.6.1</version>  
    </dependency>  

    <!--mysql驅動包-->  
    <dependency>  
      <groupId>mysql</groupId>  
      <artifactId>mysql-connector-java</artifactId>  
      <version>5.1.40</version>  
    </dependency>  
    <!--dbcp連接池-->  
    <dependency>  
      <groupId>commons-dbcp</groupId>  
      <artifactId>commons-dbcp</artifactId>  
      <version>1.4</version>  
    </dependency>  

    <!--json、基本包-->  
    <dependency>  
      <groupId>com.alibaba</groupId>  
      <artifactId>fastjson</artifactId>  
      <version>1.2.23</version>  
    </dependency>  
    <dependency>  
      <groupId>xml-apis</groupId>  
      <artifactId>xml-apis</artifactId>  
      <version>2.0.2</version>  
    </dependency>  
    <dependency>  
      <groupId>commons-net</groupId>  
      <artifactId>commons-net</artifactId>  
      <version>3.5</version>  
    </dependency>  

    <!-- 日誌文件管理包 -->  
    <dependency>  
      <groupId>org.slf4j</groupId>  
      <artifactId>slf4j-api</artifactId>  
      <version>1.7.22</version>  
    </dependency>  
    <dependency>  
      <groupId>org.slf4j</groupId>  
      <artifactId>slf4j-log4j12</artifactId>  
      <version>1.7.22</version>  
    </dependency>  
    <dependency>  
      <groupId>log4j</groupId>  
      <artifactId>log4j</artifactId>  
      <version>1.2.17</version>  
    </dependency>  

    <!-- junit4 -->  
    <dependency>  
      <groupId>junit</groupId>  
      <artifactId>junit</artifactId>  
      <version>4.12</version>  
      <scope>test</scope>  
    </dependency>  

  </dependencies>  

  <!--項目編譯及其構建-->  
  <build>  
    <plugins>  
      <plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-war-plugin</artifactId>  
        <version>2.4</version>  
        <configuration>  
          <warName>SSM</warName>  
          <!-- <packagingExcludes>  
          **/resources/**  
      </packagingExcludes> -->  
          <webResources>  
            <resource>  
              <directory>src/main/resources/resources/config</directory>  
              <targetPath>WEB-INF/classes/resources/config</targetPath>  
              <filtering>true</filtering>  
            </resource>  
            <resource>  
              <directory>src/main/java</directory>  
              <includes>  
                <include>**/*.xml</include>  
              </includes>  
              <targetPath>WEB-INF/classes</targetPath>  
            </resource>  
          </webResources>  
        </configuration>  
      </plugin>  

      <plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-resources-plugin</artifactId>  
        <version>2.4.3</version>  
        <configuration>  
          <encoding>UTF-8</encoding>  
        </configuration>  
      </plugin>  
      <plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-compiler-plugin</artifactId>  
      </plugin>  
      <plugin>  
        <groupId>org.apache.felix</groupId>  
        <artifactId>maven-bundle-plugin</artifactId>  
        <inherited>true</inherited>  
        <extensions>true</extensions>  
      </plugin>  
      <plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-surefire-plugin</artifactId>  
        <configuration>  
          <testFailureIgnore>true</testFailureIgnore>  
        </configuration>  
      </plugin>  
      <plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-site-plugin</artifactId>  
        <!-- 此處由3.2升級爲3.3.原因是maven版本3.1的,需要3,3才能兼容.否則會報錯:java.lang.NoClassDefFoundError:  
            org/sonatype/aether/graph/DependencyFilter -->  
        <version>3.3</version>  
        <configuration>  
          <locales>zh_CN</locales>  
        </configuration>  
      </plugin>  

    </plugins>  
  </build>  

</project>  

2.項目的目錄結構

項目的目錄結構

2. Spring與MyBatis的整合

2.1、建立JDBC屬性文件

jdbc.properties(文件編碼修改爲utf-8)

 #mysql  
jdbc.driverClassName=com.mysql.jdbc.Driver
 #注意這裏改成自己的端口號以及項目名稱  
jdbc.url:jdbc:mysql://localhost/ssm_demo  
jdbc.username=root  
jdbc.password=123456  
jdbc.maxActive=10  
jdbc.maxIdle=10  
jdbc.maxWait=5000  
jdbc.initialSize=5  
jdbc.validationQuery=SELECT 1  
jdbc.testWhileIdle=true  
jdbc.testOnBorrow=true  
jdbc.timeBetweenEvictionRunsMillis=3600000  
jdbc.numTestsPerEvictionRun=50  
jdbc.minEvictableIdleTimeMillis=120000  
jdbc.removeAbandoned=true  
jdbc.removeAbandonedTimeout=6000000  

2.2 Log4j的配置

  爲了方便調試,一般都會使用日誌來輸出信息,Log4j是Apache的一個開放源代碼項目,通過使用Log4j,我們可以控制日誌信息輸送的目的地是控制檯、文件、GUI組件,甚至是套接口服務器、NT的事件記錄器、UNIX Syslog守護進程等;我們也可以控制每一條日誌的輸出格式;通過定義每一條日誌信息的級別,我們能夠更加細緻地控制日誌的生成過程。
  Log4j的配置很簡單,而且也是通用的,下面給出一個基本的配置,換到其他項目中也無需做多大的調整,如果想做調整或者想了解Log4j的各種配置,參看 AndyLizh 轉載的一篇博文,很詳細:

http://blog.csdn.net/zhshulin/article/details/37937365

log4j.properties

log4j.rootLogger=DEBUG,Console,FILE  
#Console  
log4j.appender.Console=org.apache.log4j.ConsoleAppender  
log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n  
#File Appender  
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender  
log4j.appender.FILE.File=C:/soft/logs/SSM.log  
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout  
log4j.appender.FILE.layout.ConversionPattern=[%d{HH:mm:ss,SSS}] [%l] [%t] [%-5p] : %m%n  

log4j.logger.java.sql.ResultSet=INFO  
log4j.logger.org.apache=INFO  
log4j.logger.java.sql.Connection=INFO  
log4j.logger.java.sql.Statement=INFO  
log4j.logger.java.sql.PreparedStatement=INFO  

注意:這兩個properties文件保存了之後,要右鍵項目–>Java Build Path –> Add Jars
將這兩個當爲jar包引入項目。

2.3 建立spring-mybatis.xml配置文件

 這個文件就是用來完成spring和mybatis的整合的。這裏面也沒多少行配置,主要的就是自動掃描,自動注入,配置數據庫。註釋也很詳細,大家看看就明白了。

spring-mybatis.xml

<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/aop    
                          http://www.springframework.org/schema/aop/spring-aop-3.1.xsd   
                         http://www.springframework.org/schema/tx    
                          http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">  


    <bean id="configProperties"  
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>classpath:resources/config/jdbc.properties</value>  
            </list>  
        </property>  
    </bean>  

    <!-- 配置數據源 -->  
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  
        <property name="driverClassName" value="${jdbc.driverClassName}"/>  
        <property name="url" value="${jdbc.url}"/>  
        <property name="username" value="${jdbc.username}"/>  
        <property name="password" value="${jdbc.password}"/>  
        <property name="initialSize" value="${jdbc.initialSize}"></property>  
        <property name="maxActive" value="${jdbc.maxActive}"/>  
        <property name="maxIdle" value="${jdbc.maxIdle}"/>  
        <property name="maxWait" value="${jdbc.maxWait}"/>  
        <property name="validationQuery" value="${jdbc.validationQuery}"></property>  
        <property name="testWhileIdle" value="${jdbc.testWhileIdle}"></property>  
        <property name="testOnBorrow" value="${jdbc.testOnBorrow}"></property>  
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"></property>  
        <property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}"></property>  
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"></property>  
        <property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>  
        <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>  
    </bean>  

    <!-- myBatis文件 -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <property name="mapperLocations" value="classpath*:com/wrpys/ssm/model/mybatis/*.xml" />  
        <property name="plugins">  
            <array>  
                <bean class="com.github.pagehelper.PageHelper">  
                    <property name="properties">  
                        <value>  
                            dialect=mysql  
                        </value>  
                    </property>  
                </bean>  
            </array>  
        </property>  
    </bean>  

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="com.wrpys.ssm.dao" />  
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />  
    </bean>  

    <!-- 配置事務管理器 -->  
    <bean id="transactionManager"  
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"></property>  
    </bean>  

    <!-- 配置事務處理面(事務通知) -->  
    <tx:advice id="appAdvice" transaction-manager="transactionManager">  
        <tx:attributes>  
            <!-- 配置事務屬性 -->  
            <!-- 默認值: isolation="DEFAULT" timeout="-1" propagation="REQUIRED" read-only="false" -->  
            <tx:method name="insert*" propagation="REQUIRED" />  
            <tx:method name="update*" propagation="REQUIRED" />  
            <tx:method name="delete*" propagation="REQUIRED" />  
            <tx:method name="batch*" propagation="REQUIRED" />  
            <tx:method name="read*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="get*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="count*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="find*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="*" read-only="true" />  
        </tx:attributes>  
    </tx:advice>  

    <!-- 配置AOP事務 -->  
    <aop:config>  
        <!-- 配置事務切點 -->  
        <aop:pointcut expression="execution(* com.wrpys.ssm.service.*Service.*(..))"  
                      id="appPoint" />  
        <!-- 結合事務切點與切面 -->  
        <aop:advisor advice-ref="appAdvice" pointcut-ref="appPoint" />  
    </aop:config>  

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  
        <property name="dataSource" ref="dataSource"></property>  
    </bean>  

    <bean id="namedTemplate"  
          class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">  
        <constructor-arg index="0" ref="dataSource"></constructor-arg>  
    </bean>  

</beans> 

2.4 applicationContext.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"  
       xsi:schemaLocation="http://www.springframework.org/schema/beans  
                         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
                         http://www.springframework.org/schema/context  
                         http://www.springframework.org/schema/context/spring-context-4.0.xsd">  

    <context:annotation-config />  
    <!-- 配置component所在的包,自動加載需要管理的Bean -->  
    <context:component-scan base-package="com.wrpys.ssm"></context:component-scan>  
    <import resource="spring-mybatis.xml" />  

</beans>  

2.5 rest-servlet.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:mvc="http://www.springframework.org/schema/mvc"  
       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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">  

    <!-- 自動掃描該包下面的類 -->  
    <context:component-scan base-package="com.wrpys.ssm" />  

    <mvc:resources location="/common/" mapping="/common/**" />  
    <mvc:resources location="/pages/" mapping="/pages/**" />  

    <!--默認的mvc註解映射的支持 -->  
    <mvc:annotation-driven>  
        <mvc:message-converters register-defaults="true">  
            <ref bean="stringHttpMessageConverter" />  
            <ref bean="fastJsonHttpMessageConverter" />  
        </mvc:message-converters>  
    </mvc:annotation-driven>  
    <bean id="stringHttpMessageConverter"  
          class="org.springframework.http.converter.StringHttpMessageConverter">  
        <constructor-arg value="UTF-8" index="0"></constructor-arg><!-- 
         避免出現亂碼 -->  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/plain;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean>  
    <bean id="fastJsonHttpMessageConverter"  
          class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>application/json;charset=UTF-8</value>  
                <value>text/html;charset=UTF-8</value><!-- 避免IE出現下載JSON文件的情況 -->  
            </list>  
        </property>  
        <property name="features">  
            <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">  
                <value>WriteMapNullValue</value>  
                <value>QuoteFieldNames</value>  
                <value>DisableCircularReferenceDetect</value>  
            </array>  
        </property>  
    </bean>  

    <!-- Default ViewResolver對模型視圖名稱的解析即在模型視圖名稱添加前後綴 -->  
    <bean id="viewResolver"  
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="viewClass"  
                  value="org.springframework.web.servlet.view.JstlView" />  
        <property name="prefix" value="/pages/" />  
        <property name="suffix" value=".jsp"></property>  
    </bean>  

</beans>  

2.6 web.xml:由於“/resources”是資源根目錄在我機子上地址中有“/resources”會報錯,無法找到資源,把雙引號中的內容刪除即可。

<?xml version="1.0" encoding="UTF-8"?>  
<web-app version="2.5"  
         xmlns="http://java.sun.com/xml/ns/javaee"  
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
  <context-param>  
    <param-name>webAppRootKey</param-name>  
    <param-value>WeddingPhoto.root</param-value>  
  </context-param>  
  <context-param>  
    <param-name>contextConfigLocation</param-name>  
    <param-value>  
      classpath:/resources/applicationContext.xml  
    </param-value>  
  </context-param>  

  <context-param>  
    <param-name>log4jConfigLocation</param-name>  
    <param-value>classpath:/resources/config/log4j.properties</param-value>  
  </context-param>  
  <listener>  
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
  </listener>  
  <listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  </listener>  
  <!-- spring字符集過濾器 -->  
  <filter>  
    <filter-name>CharacterEncodingFilter</filter-name>  
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
    <init-param>  
      <param-name>encoding</param-name>  
      <param-value>UTF-8</param-value>  
    </init-param>  
    <init-param>  
      <param-name>forceEncoding</param-name>  
      <param-value>true</param-value>  
    </init-param>  
  </filter>  
  <filter-mapping>  
    <filter-name>CharacterEncodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
    <dispatcher>REQUEST</dispatcher>  
    <dispatcher>FORWARD</dispatcher>  
  </filter-mapping>  

  <servlet>  
    <servlet-name>dispatcher</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <init-param>  
      <param-name>contextConfigLocation</param-name>  
      <param-value>classpath:resources/rest-servlet.xml</param-value>  
    </init-param>  
  </servlet>  
  <servlet-mapping>  
    <servlet-name>dispatcher</servlet-name>  
    <!--         <url-pattern>*.do</url-pattern> -->  
    <url-pattern>/</url-pattern>  
  </servlet-mapping>  

</web-app>  

右鍵項目run as-> Maven Build

若有報錯誤:
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) on project ssmTest3: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.4:war failed: basedir

將pom.xml最下面的build中plugins內容中的groupId改爲自己new Maven Project時候的groupId。

<plugin>
            <groupId>ssmTest3</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warName>SSM</warName>
                <!-- <packagingExcludes> **/resources/** </packagingExcludes> -->
                <webResources>
                    <resource>
                        <directory>src/main/resources/resources/config</directory>
                        <targetPath>WEB-INF/classes/resources/config</targetPath>
                        <filtering>true</filtering>
                    </resource>
                    <resource>
                        <directory>src/main/java</directory>
                        <includes>
                            <include>**/*.xml</include>
                        </includes>
                        <targetPath>WEB-INF/classes</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

若還有報路徑的錯誤,注意查看我上文寫的2.6關於”resources”的內容,我遇到的只有jdbc.properties以及log4j.properties的路徑問題,要到web.xml中刪除他們兩個對應路徑前面的”/resources”。

還有一個坑我在寫這篇博客時候又重新創建了一個SSM項目時踩到了,在web.xml中

<context-param>  
    <param-name>webAppRootKey</param-name>  
    <param-value>WeddingPhoto1.root</param-value>  </context-param>  

param-value的值我與之前的項目設置相同,會報錯。我是隨便改了個值,還不知會不會有影響。但不會報錯了。

到此SSM框架整合完畢。

發佈了23 篇原創文章 · 獲贊 16 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章