spring2.5.6使用总结
来源:互联网 发布:java颜色代码 编辑:程序博客网 时间:2024/06/05 05:50
http://www.cnblogs.com/zfc2201/archive/2011/08/17/2143473.html
最少所需jar包
jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/springjdbc.username=rootjdbc.password=123
beans.xml(applicationContest.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"> <!-- 开启注解方式使用IOC --> <context:annotation-config /> <context:component-scan base-package="com.anllin" /> <!-- 开启注解方式使用AOP --> <!--<aop:aspectj-autoproxy/>--> <!-- 自动读取jdbc.properties里的配置 --> <!--<context:property-placeholder location="classpath:jdbc.properties"/>--> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean> <!-- 配置dataSource --> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/spring" /> <property name="username" value="root" /> <property name="password" value="123" /> </bean> --> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <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> <!-- 配置sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.anllin.registration.model</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- spring事务的annotation配置 ,需要多个配置时会比较繁琐,少量配置时会方便很多--> <!-- <tx:annotation-driven transaction-manager="txManager"/>--> <!-- 开启事务管理 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!--xml方式配置切面 --> <!-- <bean id="userService" class="com.anllin.service.UserService"></bean> <bean id="logInterceptor" class="com.anllin.aop.LogInterceptor"></bean> <aop:config> <aop:aspect id="logAspect" ref="logInterceptor"> <aop:pointcut expression="execution(* com.anllin.registration.service..*.*(..))" id="servicePointCut" /> <aop:before method="before" pointcut-ref="servicePointCut" /> </aop:aspect> </aop:config> --> <!-- spring事务的xml配置 ,建议使用--> <aop:config> <aop:pointcut id="bussinessService" expression="execution(* com.anllin.registration.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> </aop:config> <!-- 对不同的方法进行不同的事务管理 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" propagation="NEVER" /> <tx:method name="isExists*" read-only="true" propagation="NEVER" /> <tx:method name="*" propagation="REQUIRED" read-only="false" /> </tx:attributes> </tx:advice> <!-- 实现hibernateTemplate注入 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!--实现HibernateDaoSupport注入 --> <!-- <bean id="abstractDao" class="com.anllin.dao.impl.AbstractDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> --></beans>
- spring2.5.6使用总结
- spring2.5.6使用总结
- Spring2.5.6定时器的使用
- spring定时器的使用(spring2.5.6)
- spring定时器的使用(spring2.5.6)
- spring2总结(1-10)
- spring2总结(20-30)
- spring2总结(30-40)
- spring2总结(30-36)
- Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2 整合总结
- Spring2 + Struts2 基本配置总结
- Spring2.5.6使用Annotation时的xml文件头
- 使用spring2.5.6整合jdbc的基本配置
- 使用spring2.5 autowired 注意事项
- struts2整合spring2.5.6
- spring2
- spring2
- Spring2
- 一个画小人的游戏
- 35岁IT人不妨走技术管理咨询路
- 不用appstore照样发布应用,无限应用下载实战
- 非计算机专业想学计算机专业如何下手?
- ADO数据库编程-总结1
- spring2.5.6使用总结
- 2. Oracle数据运用那种主键生成策略,至少5种
- Ant使用指南
- 黑马程序员_第六天_高新技术之理解对JavaBean的内省操作
- 用script、div验证用户名,密码方法
- C++: 替换字符串里面的字符
- OpenSSL 证书管理流程
- 深入浅出Android Service (3)
- Eclipse错误提示:Access restriction