Spring 映射文件的书写模板
2014-01-05 16:19
323 查看
在实际J2ee开发中,spring的映射文件会命名为applicationContext.xml
但是一般由于项目会非常的大,我们会把一部分内容单独拿出来,写一个新的xml文件,再在applicationContext.xml
中用"import"标签加载其他的关于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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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"> <import resource="applicationContext-db.xml"/> <import resource="applicationContext-person.xml"/> </beans>
下面我把applicationContex-db.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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" 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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 1 配置本地化代理工厂bean 这是spring整合hibenate的入口 加载hibernate.cfg.xml 创建sessionFactory对象--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 配置 hibernate.cfg.xml文件 classpath:表示从类路径下加载文件--> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean> <!-- 2 配置hibernage模板 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <!-- 注入sessionFactory --> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 3 配置hibernage的事务管理器 在aop术语中切面 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 4 配置通知 --> <tx:advice id="advice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" read-only="false"/> <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" read-only="false"/> <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" read-only="false"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!--5 配置切入点 --> <aop:config> <!-- 配置切入点 ,这里的切入点应用的类级别--> <aop:pointcut id="perform" expression="execution( * prac.service..*.*(..))"/> <!-- 建立通知和切入点的结合 --> <aop:advisor advice-ref="advice" pointcut-ref="perform"/> </aop:config> </beans>
下面我把applicationContex-person.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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"> <bean id="personDao" class="prac.dao.impl.PersonDaoImpl"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="personService" class="prac.service.impl.PersonServiceImpl"> <property name="personDao"> <ref bean="personDao"/> </property> </bean> <bean id="personAction" class="prac.struts2.action.PersonAction" scope="prototype"> <property name="personService"> <ref bean="personService"/> </property> </bean> </beans>
相关文章推荐
- 在spring中加入多个映射文件
- Spring加载Hibernate映射文件最佳方式
- 解决 IntelliJ IDEA 无法热加载 Spring Boot 模板文件和静态资源文件
- 解决spring-boot thymeleaf模板对非严格HTML5格式文件的解析
- SpringMVC+Spring+MyBatis 项目pom.xml 文件模板
- ssh框架中spring整合hibernate的配置文件模板(带详细注释)
- spring 剑走偏锋 mappingDirectoryLocations来配置Hibernate映射文件
- Spring配置文件模板
- Spring事务--非注解--实体类及映射文件
- 使用Spring的mappingDirectoryLocations来配置Hibernate映射文件
- spring 扫描hibernate的映射文件
- Spring的applicationContext.xml中配置映射文件
- Spring boot 通用配置文件模板
- smarty模板文件书写javascript代码
- spring配置hibernate映射文件
- spring+mybatis整合,不需要配置映射文件,多路径配置
- spring boot中获取模板文件
- Spring中的packagesToScan的方式配置hibernate的class文件映射规则的理解
- 在weblogic中使用spring查找hibernate映射文件的陷阱
- Hibernate 中 映射文件的模板