SSM框架整合方式(一):XML配置文件代码
2017-11-04 14:12
645 查看
以下是第一种SSM整合的xml配置文件代码
bean.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-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- 开启注解模式 --> <context:annotation-config></context:annotation-config> <!-- 开启包扫描 --> <context:component-scan base-package="com.itjob.service.impl"></context:component-scan> <context:component-scan base-package="com.itjob.dao.impl"></context:component-scan> <!-- 读数据库配置文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!--配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${driver}"></property> <property name="url" value="${url}"></property> <property name="username" value="${usernamex}"></property> <property name="password" value="${passwordx}"></property> </bean> <!-- 配置事物管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 开启注解驱动 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- 配置mybatis --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 配置数据源 --> <property name="dataSource" ref="dataSource"></property> <!-- 各实体类取别名 别名是类的简单名称 --> <property name="typeAliasesPackage" value="com.itjob.entity"></property> <!-- 找到mapper.xml文件 --> <property name="mapperLocations" value="classpath:com/itjob/dao/*.xml"></property> </bean> <!-- 告诉mybatis mapper.xml配置文件 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.itjob.dao"></property> </bean> </beans>
jdbc.properties配置文件
driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test usernamex=root passwordx=root
web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>mAndSpringMVC</display-name> <!-- 配置springMVC 核心转换器 --> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 核心转换器启动时间 tomcat启动1秒后启动--> <load-on-startup>1</load-on-startup> </servlet> <!-- 拦截路径 --> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 配置mybatis --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean.xml</param-value> </context-param> <!-- 监听 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>/WEB-INF/jsp/index.jsp</welcome-file> </welcome-file-list> </web-app>
springMVC-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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 开启包扫描 --> <context:component-scan base-package="com.itjob.controller"></context:component-scan> <!-- 配置静态资源 spring核心转换器不会拦截 --> <!-- <mvc:resources location="/" mapping="**/*.js"/> --> <mvc:default-servlet-handler/> <!-- 开启注解驱动 --> <mvc:annotation-driven></mvc:annotation-driven> <!-- 配置controller返回jsp的前后缀 --> <bean id="internalResource" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 配置前缀 --> <property name="prefix" value="/WEB-INF/jsp/"></property> <!-- 配置后缀 --> <property name="suffix" value=".jsp"></property> </bean> </beans>
项目目录的格式:
相关文章推荐
- SSM框架整合方式(二):XML配置文件代码
- ssm框架整合的配置文件applicationContext.xml
- SSM框架,基于JavaConfig配置方式,不用xml配置文件
- SSM框架笔记07:初探Spring——采用XML配置文件与注解方式
- Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)
- 整合ssm框架之配置文件
- 2017-06-01-SSM框架-jar以及xml配置文件
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- 【SSM整合】-Maven管理SSM框架的pom.xml配置
- SSM整合之applicationContext.XML配置文件详解
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- s2sh框架整合详细配置-xml方式
- SSM框架整合开发的文件配置
- 【SSM-MyBatis框架】Mapper.xml配置文件(mybatis的核心)
- SSM整合所需要的xml文件以及配置
- 使用eclipse开发spring,hibernate,mybatis等框架的xml配置文件时代码不自动提示
- 【SSM整合】-三框架整合xml文件结构及相应web.xml配置
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- Spring+Spring Mvc+Mybatis+MySqlite(SSM框架整合Xml配置)
- spring+quartz两种整合方式:代码创建job+xml配置创建job