ssm框架配置文件详解
时间: 2023-11-17 12:55:08 浏览: 57
SSM框架配置文件主要包括web.xml、spring配置文件、mybatis.xml和jdbc.properties文件。在web.xml中配置了启动spring容器和springMvc前端控制器等信息。spring配置文件中包含了完整的配置,包括开启注解模式、加载属性文件、配置数据库连接池、配置sqlSessionFactory、配置mapper扫描器、配置事务和配置模板引擎等内容。mybatis.xml文件用于额外配置日志输出。而jdbc.properties文件用于配置数据库的相关信息,如驱动、URL、用户名和密码等。
相关问题
ssm框架xml配置文件
SSM框架是由Spring、SpringMVC和MyBatis三个框架组合而成,其中Spring和MyBatis需要进行XML配置。下面是它们的配置文件:
1. Spring配置文件 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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- 配置数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" 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 SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.example.model"/>
<property name="mapperLocations" value="classpath*:mapper/*.xml"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 开启Spring注解扫描 -->
<context:component-scan base-package="com.example"/>
</beans>
```
2. MyBatis配置文件 sqlMapConfig.xml
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
</settings>
<!-- 配置MyBatis Mapper映射文件 -->
<mappers>
<mapper resource="mapper/UserMapper.xml"/>
</mappers>
</configuration>
```
其中,mapper/UserMapper.xml是自己编写的Mapper映射文件,用于定义SQL语句和映射关系。
ssm框架的核心配置文件
ssm框架的核心配置文件主要包括以下几个文件:web.xml、applicationContext.xml、mybatis-config.xml、spring-dao.xml、spring-service.xml以及spring-mvc.xml。其中,web.xml是web端的配置文件,用于配置Servlet、Filter和Listener等;applicationContext.xml是spring的总配置文件,用于配置Spring容器;mybatis-config.xml是mybatis的核心配置文件,主要配置settings和typeAliases等内容;spring-dao.xml是dao层的配置文件,用于配置数据访问层的相关bean;spring-service.xml是service层的配置文件,用于配置业务逻辑层的相关bean;spring-mvc.xml是controller层的配置文件,用于配置控制器层的相关bean。
在mybatis-config.xml文件中,主要配置了两个内容:settings和typeAliases。settings用于配置mybatis的一些设置,比如日志实现方式等;而typeAliases用于配置别名,使得在mybatis的映射文件中可以使用简化的类名进行配置。
需要注意的是,这些核心配置文件的顺序可以根据个人习惯进行编写,没有固定的规定顺序。但是一般建议按照上述的顺序来编写,以保持代码的整洁和易读性。