ssm中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:aop="http://www.springframework.org/schema/aop"
	   xmlns:p="http://www.springframework.org/schema/p"
	   xmlns:tx="http://www.springframework.org/schema/tx"
	   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-2.5.xsd
                http://www.springframework.org/schema/aop 
                http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.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">
	<context:component-scan base-package="com.hfxt.service"/>
	<context:property-placeholder location="classpath:database.properties"></context:property-placeholder>
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="username" value="${user}"></property>
		<property name="password" value="${password}"></property>
		<property name="url" value="${url}"></property>
		<property name="driverClassName" value="${driver}"></property>
	</bean>
	<!--创建SqlSessionFactory MyBatis会话工厂对象-->
	<bean id = "sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!--引用数据源-->
		<property name="dataSource" ref="dataSource"></property>
		<!--引用mybatis的配置文件-->
		<!--<property name="configLocation">
			<value>classpath:mybatis-config.xml</value>
		</property>-->
		<!--解析dao接口的xml文件-->
		<property name="mapperLocations" value="classpath:com/hfxt/dao/*Mapper.xml"></property>
		<!--配置别名-->
		<property name="typeAliasesPackage" value="com.hfxt.entity"/>
	</bean>

	<!--定义dao组件-->
	<!--<bean id="usesDao" class="com.hfxt.dao.impl.UsesDaoImpl">
		<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
	</bean>-->
	<!--MapperScannerConfigurer用来映射dao层实现类-->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
		<property name="basePackage" value="com.hfxt.dao"/>
	</bean>
	<!--创建事务管理器-->
	<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>
	<tx:annotation-driven transaction-manager="txManager"/>
</beans>

database.properties文件内容:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/film?characterEncoding=utf-8
user=root
password=root

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值