SSM的基本集成配置文件
2019-02-28 19:20
127 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/user_path/article/details/88042377
SSM集成
ssm【Spring+SpringMVC+MyBatis】是市面上使用最多的框架
集成配置文件
1.准备properties文件【略】
2.配置Spring.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: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/tx http://www.springframework.org/schema/tx/spring-tx.xsd" > <!-- 集成SSM 1.准备properties属性文件 2.dataSource数据源配置 3.spring与mybatis的集成配置【绑定SqlSessionFactory】 4.service的扫描配置 --> <!--扫描service层--> <context:component-scan base-package="com.cn.service"/> <!--引入properties属性文件--> <context:property-placeholder location="classpath:dp.properties"/> <!--dataSource数据源--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!--驱动--> <property name="driverClassName" value="${jdbc.driverClassName}"/> <!--路径--> <property name="url" value="${jdbc.url}"/> <!--数据库用户名--> <property name="username" value="${jdbc.username}"/> <!--数据库密码--> <property name="password" value="${jdbc.password}"/> </bean> <!--集成MyBatis的核心对象--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!--配置数据源--> <property name="dataSource" ref="dataSource"/> <!--配置别名--> <property name="typeAliasesPackage" value="com.cn.domain"/> <!--配置Mapper映射的扫描--> <property name="mapperLocations" value="classpath:com/cn/mapper/*.xml"/> </bean> <!--一劳永逸的配置Mapper的方案--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!--扫描的包的配置--> <property name="basePackage" value="com.cn.mapper" /> </bean> <!--配置事务--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!--配置事务支持--> <tx:annotation-driven/> </beans>
3.配置Spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 "> <!--配置扫描controller层--> <context:component-scan base-package="com.cn.controller"/> <!--静态资源放行--支持restful风格--> <mvc:default-servlet-handler/> <!--Spring-Mvc注解支持--> <mvc:annotation-driven/> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/system/" /> <property name="suffix" value=".jsp" /> </bean> <!--上传解析器【略】--> </beans>
3.配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app 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_4_0.xsd" version="4.0"> <!--监听Spring--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--启动SpringMVC的配置--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <!--支持restful风格--> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 解决post请求乱码 --> <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> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
4.配置后启动服务器常见问题
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
说找不到你的监听器
解决:
启动服务器就行了,遇到类似的问题也能解决
相关文章推荐
- maven-ssm框架基本整合之配置文件的配置
- SSM项目整合【含最新版所有常用的相关jar包(maven依赖),以及所有基本配置文件】
- ssm集成配置文件
- 最基本的Maven+SSM Pom文件配置
- 实习日三-MAVEN配置和SSM基本文件
- SSM 集成的两个配置文件
- ssm-xml配置文件基本信息
- ssm pom.xml配置文件集成
- 高可用之KeepAlived(一):基本概念和配置文件分析
- SVN服务器端,客户端的安装与配置,SVN的基本操作与集成
- 新手基本struts.xml的配置文件详解
- 在tomcat中集成JDK配置starttup.bat文件
- Spring集成Mybatis配置文件的简单理解
- SSM框架整合开发的文件配置
- VIM配置文件——基本配置
- SSM框架搭建------包含工程项目结构,项目需求的各种配置文件
- ssm的数据库配置文件config.properties
- 文件存到本地---SSM配置Ueditor实现图片的上传
- 关于SSM的配置文件和Web.xml的配置
- IDEA开发工具整合ssm+maven基本配置