Day72 SSM框架搭建(沒有mybatisConfig.xml)

神一樣的我發表於2018-05-10

需要的jar包-MySQL

aopalliance.jar
asm-3.3.1.jar
aspectjweaver.jar
cglib-2.2.2.jar
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-logging-1.1.1.jar
commons-logging-1.1.3.jar
jackson-annotations-2.4.0.jar
jackson-core-2.4.1.jar
jackson-databind-2.4.1.jar
javassist-3.17.1-GA.jar
jstl-1.2.jar
kaptcha-2.3.jar
log4j-1.2.17.jar
log4j-api-2.0-rc1.jar
log4j-core-2.0-rc1.jar
mybatis-3.2.7.jar
mybatis-spring-1.2.3.jar
mysql-connector-java-5.1.30.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
spring-aop-4.1.6.RELEASE.jar
spring-aspects-4.1.6.RELEASE.jar
spring-beans-4.1.6.RELEASE.jar
spring-context-4.1.6.RELEASE.jar
spring-core-4.1.6.RELEASE.jar
spring-expression-4.1.6.RELEASE.jar
spring-jdbc-4.1.6.RELEASE.jar
spring-tx-4.1.6.RELEASE.jar
spring-web-4.1.6.RELEASE.jar
spring-webmvc-4.1.6.RELEASE.jar
standard-1.1.2.jar

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:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
      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/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
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        "
        default-autowire="byName"
        >

        <!--配置註解掃描  -->
        <context:component-scan base-package="com.bjsxt.serviceImpl,com.bjsxt.pojo"></context:component-scan>
        <!--配置代理模式為cglib  -->
        <aop:aspectj-autoproxy proxy-target-class="true" ></aop:aspectj-autoproxy>
        <!--配置資料來源檔案掃描  -->
        <context:property-placeholder location="classpath:db.properties"/>
        <!--配置資料來源  -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
        </bean>
        <!--配置工廠  -->
        <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
        </bean>
        <!--配置mapper包掃描  -->
       <bean id="mapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       <property name="basePackage" value="com.bjsxt.mapper"></property>
       <property name="sqlSessionFactoryBeanName" value="factory"></property>
       </bean>
       <!--配置事務  -->
         <!--配置事務Bean  -->
         <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"></bean>
         <!--配置事務管理辦法  -->
         <tx:advice id="advice" transaction-manager="transactionManager">
         <tx:attributes>
         <tx:method name="ins*"/>
         <tx:method name="del*"/>
         <tx:method name="up*"/>
         <tx:method name="sel*" read-only="true"/>
         </tx:attributes>
         </tx:advice>
         <!--配置相關事件  -->
         <aop:config>
         <aop:pointcut expression="execution(* com.bjsxt.serviceImpl.*.*(..))" id="my"/>
         <aop:advisor advice-ref="advice" pointcut-ref="my"/>
         </aop:config>
         <!--配置切面  -->
            <!--配置切點bean  -->
            <!--配置通知bean  -->
            <!--織入形成切面  -->
         <!--配置其他bean  -->
        </beans>

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
jdbc.username=root
jdbc.password=root

log4j.properties


log4j.rootCategory=info,LOGFILE



log4j.logger.com.bjsxt.mapper=debug, CONSOLE
log4j.logger.com.bjsxt.advice=debug, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %c-%d-%m%n


log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=C:/BiZhi/axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=- %c-%d-%m%n

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        <!--配置註解掃描  -->
        <context:component-scan base-package="com.bjsxt.controller"></context:component-scan>
        <!--配置mvc註解驅動  -->
        <mvc:annotation-driven></mvc:annotation-driven>
        <!--配置靜態資源方式  -->
        <mvc:resources location="/js/" mapping="/js/**"></mvc:resources>
        <mvc:resources location="/css/" mapping="/css/**"></mvc:resources>
        <mvc:resources location="/images/" mapping="/images/**"></mvc:resources>

        <!--配置自定義檢視解析器  -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/email/"></property>
        <property name="suffix" value=".jsp"></property>
        </bean>
        <!--配置攔截器  -->
        <mvc:interceptors>
                <bean id="my2" class="com.bjsxt.intercepter.MyInter2"></bean><!-- 攔截全部 -->
                <mvc:interceptor>
                    <mvc:mapping path="/demo"/><!--指定攔截  -->
                    <bean id="my" class="com.bjsxt.intercepter.MyInter"></bean>
                </mvc:interceptor>
            </mvc:interceptors>
        <!--配置上傳資源解析物件  -->
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8"></property>
        <property name="maxInMemorySize" value="150000"></property>
        <property name="maxUploadSize" value="1024123123"></property>
        </bean>
        <!--配置異常解析器  -->
        <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
        <props>
        <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">sizeLimit</prop>
        </props>
        </property>
        </bean>
        </beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <!--配置Spring  -->
  <!--配置applicationContext,xml的路徑  -->
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!--配置監聽器  -->
  <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
  <!--配置SpringMVC 的servlet  -->
  <servlet>
    <servlet-name>servlet123</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--配置Spring MVC 的配置檔案路徑  -->
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>servlet123</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!--配置編碼過濾器  -->
  <filter>
  <filter-name>encoding</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>encoding</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

相關文章