整合SSM(Spring+Spring+Mybatis)所有到的jar包和笔记
来源:互联网 发布:逆袭网络剧什么时候播 编辑:程序博客网 时间:2024/05/18 09:12
1.导入Spring、Mybatis、log4j等相关jar包
jar包下载地址:
http://download.csdn.net/download/lp840312696/10170895
整合SSM框架需要配置如下文件:
web.xml
applicationContext.xml(配置Spring)
springmvc-servlet.xml(配置SpringMVC)
log4j.properties(配置log输出)
mybatis.xml(配置Mybatis)
*Mapper.xml(配置sql)
2.配置web.xml文件
配置DispatcherServlet,引入SpringMVC文件。
<!--配置springmvcDispatcherServlet的设置和配置映射 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <!-- <load-on-startup>1</load-on-startup> --> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
配置ContextLoaderListener监听器,引入Spring配置文件
<!-- 配置扫描SpringIOC的资源文件 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
配置编码集
<!-- 配置编码集 --> <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> </filter-mapping>
3.applicationContext.xml文件
配置Spring扫描的包路径
<!-- 扫描SpringIOC --> <context:component-scan base-package="com.ssm"></context:component-scan>
配置Mybatis,数据库连接也配置在这里了,没有使用properties文件,因为我使用properties文件出现了类型转换异常。
<!-- MyBatis配置 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 显式指定Mapper文件位置 --> <property name="mapperLocations" value="classpath:/com/ssm/config/mybatis/sqlxml/*Mapper.xml" /> <!-- mybatis配置文件路径 --> <property name="configLocation" value="classpath:/com/ssm/config/mybatis/mybatis.xml"/> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> <!-- 这个执行器会批量执行更新语句, 还有SIMPLE 和 REUSE --> <constructor-arg index="1" value="BATCH" /> </bean> <!-- 扫描basePackage接口 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 映射器接口文件的包路径, --> <property name="basePackage" value="com.ssm.dao" /> </bean> <!-- 使用annotation定义事务 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- 数据源配置, 使用Tomcat JDBC连接池 --> <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"> <!-- Connection Info --> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/mybatis?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true" /> <property name="username" value="root" /> <property name="password" value="x5" /> <!-- Connection Pooling Info --> <property name="maxActive" value="50" /> <property name="maxIdle" value="10" /> <property name="minIdle" value="0" /> <property name="defaultAutoCommit" value="false" /> </bean>
4.配置springmvc-servlet.xml
在SpringMVC中只需要配置扫描包和视图路径
<!-- 扫描SpringmvcIOC --> <context:component-scan base-package="com.ssm.*"></context:component-scan> <!-- 配置视图路径 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver"> <!-- 前缀 --> <property name="prefix" value="/WEB-INF/jsp/" /> <!-- 后缀 --> <property name="suffix" value=".jsp" /> </bean>
以下为其他配置
<!-- 不处理静态资源 --> <mvc:default-servlet-handler />
5.log4j.properties
配置log4jlog4j.rootLogger=INFO,Consolelog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%nlog4j.logger.org.apache=INFO#log4j.logger.org.mybatis=DEBUGlog4j.logger.com.ssm.dao=DEBUG
6.配置mybatis.xml
只需要配置一句。
<settings> <setting name="cacheEnabled" value="true" /> </settings>
7.*Mapper.xml
这里配置sql
<select id="selectAll" resultType="com.ssm.bean.Book"> select * from Book where 1=1</select>
配置完成之后执行sql的时候很有可能会出现下面的问题:
十二月 22, 2017 11:19:33 上午 org.apache.tomcat.jdbc.pool.ConnectionPool init
严重: Unable to create initial connections of pool.
java.sql.SQLException: com.mysql.jdbc.Driver
……
这个问题是因为tomcat的lib包中没有com.mysql.jdbc.Driver驱动类,
需要将mysql-connector-java-5.1.7-bin.jar包拷贝到tomcat的lib文件夹下。
- 整合SSM(Spring+Spring+Mybatis)所有到的jar包和笔记
- 自用(Spring 和Hibernate 整合笔记和jar包)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- [150729]spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- 收集一些好的文章地址
- 泛型
- C++ increment/decrement/dereference 操作符典型写法
- 【章节6】数据库中数据的查询操作
- Leetcode 92. Reverse Linked List II
- 整合SSM(Spring+Spring+Mybatis)所有到的jar包和笔记
- 语义分割
- SQL 查重语句
- leetcode 551[easy]-- Student Attendance Record I
- eclipse 安装 lombok
- Foundation5(二十二)
- SOT23-6封装随机数发生芯片,串行接口
- Axure RP 8 for Mac(交互原型设计工具)附注册码和汉化补丁 V8.1.03366中文破解版
- 求N阶乘末尾0的个数