Spring配置文件详解

来源:互联网 发布:下载蜘蛛软件刷奖软件 编辑:程序博客网 时间:2024/05/18 20:47

web.xml文件内容配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <display-name>MySpringOne</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

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"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 配置数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 加载驱动 -->
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <!-- 连接数据库所用的url -->
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:yu_test"/>
        <!-- 连接数据库的用户名 -->  
        <property name="username" value="yu_test"/>
        <!-- 连接数据库的密码 -->  
        <property name="password" value="yu_test"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置JDBC模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 将JdbcTemplate注入到EmpDaoImp -->
<bean id="empDao" class="com.company.dao.EmpDaoImp">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
<!-- 指定需要添加事务管理的目标 -->
<bean id="target" class="com.company.service.EmpServiceImp">
<property name="empDao" ref="empDao"/>
</bean>
<bean id="empService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="target" ref="target"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="proxyInterfaces">
<list>
<value>com.company.service.EmpService</value>
</list>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
0 0
原创粉丝点击