一、需要用到的包
二、
Suppliers.java 属性 id ,name
Suppliers.xml
HelloWordDao.java
HelloWord.java
HelloWordAspect.java:
public class HelloWordAspect {
public void beforeAdvice() {
System.out.println("添加之前===before");
}
public void afterAdvice() {
System.out.println("添加之后===after");
}
}
SqlMapConfig.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings useStatementNamespaces="true" />
<sqlMap resource="com/spring/bean/Suppliers.xml" />
</sqlMapConfig>
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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- jdbc属性文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<!-- 数据源 -->
<!--事实上是因为DriverManagerDataSource建立连接是只要有连接就新建一个connection,根本没有连接池的作用
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver.class}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
-->
<!-- dbcp连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver.class}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<!-- ibatis配置文件 -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="helloworddao" class="com.spring.dao.HelloWordDao">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
<bean id="helloword" class="com.spring.service.HelloWord">
<property name="helloWordDao" ref="helloworddao"></property>
</bean>
<!-- 切面类 -->
<bean id="helloAspect" class="com.spring.test.HelloWordAspect"></bean>
<!-- aop实现 -->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* com.spring.service..*(..))"/>
<aop:aspect ref="helloAspect">
<aop:before pointcut-ref="pointcut" method="beforeAdvice"/>
<aop:after pointcut="execution(* com.spring.service..*(..))" method="afterAdvice"/>
</aop:aspect>
</aop:config>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事务特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- 配置哪些类的方法需要加事务 -->
<aop:config>
<aop:pointcut id="pointcutManager" expression="execution(* com.spring.service..*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcutManager"/>
</aop:config>
</beans>
log4j.properties:
# This is the configuring for logging displayed in the Application Server
log4j.rootCategory=WARN, stdout,logfile
#stdout configure
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d %p [%c] - <%m>%n
#logfile configure
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=${catalina.home}/logs/sniper.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern= %d %p [%c] - <%m>%n
# Control logging for other open source packages
# Changing the log level to DEBUG when debug
log4j.logger.org.springframework=INFO
# Changing the log level to DEBUG will display SQL Hibernate generated
log4j.logger.java.sql=DEBUG
log4j.logger.org.hibernate=ERROR
log4j.logger.org.hibernate.SQL=ERROR
log4j.logger.org.hibernate.cache=ERROR
log4j.logger.net.sf.ehcache=ERROR
测试类:Test_HelloWord.java
public class Test_HelloWord {
public static void main(String [] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWord h = context.getBean("helloword", HelloWord.class);
List<Suppliers> list = h.findAll();
for (Suppliers o : list) {
System.out.println(o);
}
}
}
输出结果:
2012-04-24 17:20:48,968 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshingorg.springframework.context.support.ClassPathXmlApplicationContext@a56a7c: startup date [Tue Apr 24 17:20:48 CST 2012]; root of context hierarchy>
2012-04-24 17:20:49,109 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [applicationContext.xml]>
2012-04-24 17:20:49,812 INFO [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - <Loading properties file from class path resource [jdbc.properties]>
2012-04-24 17:20:49,890 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Pre-instantiating singletons inorg.springframework.beans.factory.support.DefaultListableBeanFactory@1b09468: defining beans [propertyConfigurer,dataSource,sqlMapClient,helloworddao,helloword,helloAspect,org.springframework.aop.config.internalAutoProxyCreator,pointcut,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,org.springframework.aop.aspectj.AspectJPointcutAdvisor#1,transactionManager,txAdvice,pointcutManager,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0]; root of factory hierarchy>
添加之前===before
2012-04-24 17:20:52,531 DEBUG [java.sql.Connection] - <{conn-100000} Connection>
2012-04-24 17:20:52,546 DEBUG [java.sql.Connection] - <{conn-100000} Preparing Statement: select t.* from t_suppliers t WHERE Rownum <10 >
2012-04-24 17:20:52,843 DEBUG [java.sql.PreparedStatement] - <{pstm-100001} Executing Statement: select t.* from t_suppliers t WHERE Rownum <10 >
2012-04-24 17:20:52,843 DEBUG [java.sql.PreparedStatement] - <{pstm-100001} Parameters: []>
2012-04-24 17:20:52,843 DEBUG [java.sql.PreparedStatement] - <{pstm-100001} Types: []>
2012-04-24 17:20:52,937 DEBUG [java.sql.ResultSet] - <{rset-100002} ResultSet>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Header: [ID, NAME]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [216150, 2011newSupplier8]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [48645, 包头市九福数码科技有限公司12]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [52400, 52400]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [52405, 包头市太平洋计算机科技有限公司]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [54057, 包头市遂通汽车销售服务有限公司]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [52425, 包头市大兴汽车贸易有限公司]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [44238, 呼和浩特云顿影视科技有限公司]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [45012, 包头市华城科教设备有限公司]>
2012-04-24 17:20:53,078 DEBUG [java.sql.ResultSet] - <{rset-100002} Result: [99, 无中标商]>
添加之后===after
id:216150 name:2011newSupplier8
id:48645 name:包头市九福数码科技有限公司12
id:52400 name:52400
id:52405 name:包头市太平洋计算机科技有限公司
id:54057 name:包头市遂通汽车销售服务有限公司
id:52425 name:包头市大兴汽车贸易有限公司
id:44238 name:呼和浩特云顿影视科技有限公司
id:45012 name:包头市华城科教设备有限公司
id:99 name:无中标商
相关推荐
SSI框架整合(Struts2.1+Spring3.0+Ibatis 2.3) 下载之后执行.sql文件创建表和sequence 记得改数据库访问地址以及数据库登录用户名密码 项目访问路径 localhost:8080/SSI_Demo1 一个简单的例子(Oracle数据库增删改查...
struts2.1.8+spring3.0+ibatis2.3优雅框架 sorry包有点大没能上传,见附件截图
这是自己整合的Spring 3.0+Struts2+Mybatis 3 + p6spy +ehcache的平台框架,内含一点示例代码,目前ehcache没有使用。直接编译后发布就能用 测试环境基于JDK1.6+Tomcat 6.0. 大家拿到后请根据实际情况修改 ...
耗时3天,对Struts2+Ibatis+Spring3.0+JreeChart进行了完整整合 包括Spring3.0的事务配置 OSCache二级缓存的配置 log4j实现输出Sql到控制台 JfreeChart与Struts2,Spring3.0的整合 对一个简单的表实现查询,批量删除...
Spring 3.0 整合 iBatis 3 Beta10 配置
struts2.1.8.1+ibatis2.3.4.7+spring3.0完美整合小测试---------
经过几天的学习和查找,自己弄出来了一套,当然,俺不是啥高手,只是喜欢研究,研究的不对希望谅解,以下仅供参考:
spring3.0,ibatis2.0,dwr2.0 框架整合小demo , 使用的是oracle 数据库,希望帮助大家学习
org.springframework.orm-3.0.0.M4.jar: 整合第三方的ORM框架,如hibernate,ibatis,jdo,以及spring的JPA实现 org.springframework.transaction-3.0.0.M4.jar: 为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和...
培训信息发布平台v1.0(企业端) ...这个项目是在以前做过的一个小项目的基础上整理而得,实现的功能很简单,还很不完备,只是那时学习struts2 + Spring2.5 + iBatis2.3 + ExtJs3.0整合开发的一个习作。
SSI框架整合(Struts2.1+Spring3.0+Ibatis 2.3) 下载之后执行.sql文件创建表和sequence 项目访问路径 localhost:8888/SSI_Demo1 一个简单的例子(Oracle数据库增删改查示例) 用户的增删改查操作,适合初学者...
Ibatis和Spring整合例子,实现增删改查功能.
NULL 博文链接:https://yelifei94.iteye.com/blog/1122909
ibatis3.0+spring2.5+struts2.0整合框架、适合做网上购物商城
spring-ibatis 整合 springmvc 配置: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc=...
那么,我们就想将 MyBatis3 的支持添加 到 Spring3.0(参考 Spring Jira 中的问题)中。而不幸的是,Spring 3.0 的开发在 MyBatis 3.0 官方发布前就结束了。 因为 Spring 开发团队不想发布一个基于非发布版的 MyBatis 的...
spring3.0.M4 org.springframework.asm-3.0.0.M4.jar: 提供对ASM(一个字节码框架)的简单封装 org.springframework.expression-3.0.0.M4.jar: spring表达式语言 org.springframework.test-3.0.0.M4.jar: ...
EXT登陆,整合STRUTS2,SPRING,IBATIS,EXTJS3.0,详细的请看看代码,因为jar包较大,暂不加jar包。的请看看代码,因为jar包较大,暂不加jar包
mybatis实战教程mybatis in action之五与spring3集成附源码 mybatis实战教程mybatis in action之六与Spring MVC 的集成 mybatis实战教程mybatis in action之七实现mybatis分页源码下载 mybatis实战教程mybatis in ...