SSM框架整合开发的文件配置

1.SSM开发所需的包

Spring框架jar包

spring-framework-4.x.x.RELEASE文件夹下libs目录下所有模块的jar包和Spring的核心容器必须依赖的common-logging的jar包

Mybatis框架jar包,共计21个

mybatis-3.x.x.jar和mybatis-3.x.x文件夹下的lib目录下的所有jar包,共计13个

MyBatis整合Spring中间件jar包

在Mybatis文件里面的mybatis-spring-x.jar类似的包,用于满足Mybatis用户整合Spring的需求。中间件有两个作用:

   1.在Spring中配置Mybatis工厂类

   2.在DAO层使用Spring注入的工具bean对数据进行操作

Spring的APO事务jar包

aspectj框架的jar包

aspectjt.jar、aspectjtools.jar、aspectjweaver.jar、org.aspectjmatcher.jar

aop联盟的jar包

aopaliance.jar

数据库驱动jar包

mysql-connector-java-x.x.x.jar

数据源c3p0所需jar包

c3p0-x.x.x.jar、hibernate-c3p0-x.x.x.Final.jar、mchange-commons-java.x.x.x.jar

JSTL标签库jar包

javax.servlet.jsp.jstl-x.x.x.jar、java.servlet.jsp.jstl-api-x.x.x.jar

2.数据库属性文件db.properties

dataSource.driverClass = com.mysql.jdbc.Driver
dataSource.jdbcUrl = jdbc:mysql://localhost:3306/mydatabase
dataSource.user = root
dataSource.password = chengxi
dataSource.maxPoolSize = 20
dataSource.maxIdleTime = 1000
dataSource.minPoolSize = 6
dataSource.initialPoolSize = 5

3.log4j配置文件:log4j.properties

# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.org.blog.dao.GuitarMapper=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n


3.web.xml文件配置

<?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">

  <!-- 配置Spring核心监听器 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 指定spring配置文件,默认/WEB-INF.applicationcontext.xml -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/spring-config.xml</param-value>
  </context-param>

  <!-- 配置Springmvc核心控制器 -->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/springmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Springmvc核心控制器拦截所有的请求 -->
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 配置编码过滤器 -->
  <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>
  </filter>

  <!-- 配置所有html编码格式为utf-8 -->
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.html</url-pattern>
            <page-encoding>UTF-8</page-encoding>
        </jsp-property-group>
    </jsp-config>

    <!-- web首页 -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.php</welcome-file>
    <welcome-file>index.asp</welcome-file>
  </welcome-file-list>

</web-app>

4.Spring框架配置文件spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans" xmlns:mybatis="http://mybatis.org/schema/mybatis-spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" 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-4.1.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

    <!-- 将org.blog.mapper包下的所有接口当做mapper配置,之后可以自动注入mapper类 -->
    <mybatis:scan base-package="org.blog.Mapper" />

    <!-- 将org.blog包下的所有spring注解类注册为springbean -->
    <context:component-scan base-package="org.blog" />

    <!-- 使用后处理器加载数据源参数 -->
        <context:property-override location="classpath:db.properties" />

        <!-- 配置c3p0数据源 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" />

        <!-- 配置SqlSessionFactory,专门用于整合spring+mybatis -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource" />

        <!-- JDBC事务管理器 -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />

        <!-- 启用支持annotation注解方式事务管理 -->
        <tx:annotation-driven transaction-manager="transactionManager" />       

</beans>

5.SpringMVC框架配置文件springmvc-config.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:mvc="http://www.springframework.org/schema/mvc" 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.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

   <!-- 自动扫描该包下的所有controller注解类并注册为controller -->
   <context:component-scan base-package="org.blog.Controller" />

   <!-- 设置默认的配置方案 -->
   <mvc:annotation-driven />
   <!-- 指定静态文件不过滤 -->
   <mvc:default-servlet-handler />

   <!-- 指定视图解析器 -->
   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- 前缀 -->
    <property name="prefix" value="/WEB-INF/protpage/" />
    <!-- 后缀 -->
    <property name="suffix" value=".jsp" />
   </bean>

   <!-- 配置文件上传解析器 -->
   <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- 上传文件大小上限 -->
    <property name="maxUploadSize" value="10485760" />
    <!-- 上传文件编码格式 -->
    <property name="defaultEncoding" value="UTF-8" />
   </bean>

</beans>

6.src文件下的包定义分类

1.org.blog.Controller:SpringMVC控制器
2.org.blog.Dao:Spring注册的工具bean
3.org.blog.Mapper:Mybatis的mapper映射类
4.org.blog.Service:服务层接口
4.org.blog.ServiveImp:服务层接口实现类

你可能感兴趣的:(spring,框架,mybatis,jar)