- 浏览: 329008 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
zhengqiweiyi:
请问这里的客户端和服务器是指同一台电脑上的吗?
JSP动态显示服务器时间和客户端时间 -
18101095336:
一语道破天机[color=blue][/c ...
restlet使用中遇到的一些问题 -
jjjssh:
废话一大堆,就是没说到少了那个jar包
The hierarchy of the type is inconsistent -
junjielee:
重点还没说啊~~~~~~~~
The hierarchy of the type is inconsistent -
幽绿琵琶:
太棒了
loadrunner 9.5 9.0 8.1下载地址 和license
最近看了一下springside,学习很多,从思想到编码风格,这里再废话一下,思想这个东西蛮虚,但是并不是只可意会不可言传,一些东西你想明白了,能够给别人讲解,并且让他人听懂了,这才代表你的思想到了某个境界,当然这个是我这个阶段的认识,所谓万物不变的是变化,思想也一样,扯远了。
这个demo延续上次,算是我对上一个项目的一点个人改进。这里只是简单的改进,使用第一个demo的注解,体会一下注解在减少配置方面的作用。
1.数据库和表仍然使用demo2
2.实体类和demo2一样,更改一下包名。
3.接口类不变。
4.实现类使用注解
package com.isa.demo3.service; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.isa.demo3.domain.User; @Service //默认将类中的所有函数纳入事务管理. @Transactional public class UserServiceImpl implements UserService { @Autowired private SessionFactory sessionFactory; @Override @Transactional(readOnly = true) public List<User> getAllUsers() { Session session = sessionFactory.getCurrentSession(); String hql = "from User"; List<User> list = session.createQuery(hql).list(); return list; } @Override @Transactional(readOnly = true) public User getUserById(long id) { Session session = sessionFactory.getCurrentSession(); User user = (User) session.get(User.class, id); return user; } }
5.配置文件的变化比较大,第一个用application.properties保存数据库相关配置,这里参考springside
#h2 version database settings #jdbc.driver=org.h2.Driver #jdbc.url=jdbc:h2:tcp://localhost/~/mini-web #jdbc.username=sa #jdbc.password= #hibernate.dialect=org.hibernate.dialect.H2Dialect #oracle version database settings #jdbc.driver=oracle.jdbc.driver.OracleDriver #jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:XE #jdbc.username=miniweb #jdbc.password=miniweb #hibernate.dialect=org.hibernate.dialect.Oracle10gDialect #mysql version database setting jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=utf-8 jdbc.username=root jdbc.password=123456 hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect #hibernate settings hibernate.show_sql=true hibernate.format_sql=false hibernate.ehcache_config_file=/ehcache/ehcache-hibernate-local.xml
第二个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:jee="http://www.springframework.org/schema/jee" 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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-lazy-init="true"> <description>Spring公共配置 </description> <!-- 定义受环境影响易变的变量 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <!-- 标准配置 --> <value>classpath*:demo3/application.properties</value> <!-- 集群中节点配置 --> <value>classpath*:demo3/application.cluster.properties</value> <!-- 本地开发环境配置 --> <value>classpath*:demo3/application.local.properties</value> <!-- 服务器生产环境配置 --> <!-- <value>file:/var/myapp/application.server.properties</value> --> </list> </property> </bean> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --> <context:component-scan base-package="com.isa.demo3" /> <!-- 数据源配置,使用应用内的DBCP数据库连接池 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- Connection Info --> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- Connection Pooling Info --> <property name="initialSize" value="5" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="30" /> <property name="maxWait" value="1000" /> <property name="poolPreparedStatements" value="false" /> <property name="defaultAutoCommit" value="false" /> </bean> <!-- 数据源配置,使用应用服务器的数据库连接池 --> <!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />--> <!-- Hibernate配置 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">${hibernate.ehcache_config_file}</prop> </props> </property> <property name="packagesToScan" value="com.isa.demo3.domain" /> </bean> <!-- 事务管理器配置,单数据源事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> </beans>
6.简单测试
package com.isa.demo3.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.isa.demo3.service.UserService; import com.isa.demo3.service.UserServiceImpl; public class Demo3Test { /** * @param args */ public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "demo3/*.xml" }); UserService service = (UserServiceImpl)context.getBean("userServiceImpl"); System.out.println(service.getUserById(1L).toString()); } }
7.对应配置文件需要注意,sessionFactory节点的packagesToScan的写法,到domain的包即可,后面不需要加*号。
发表评论
-
ConcurrentHashMap的高性能
2012-07-17 18:11 1436ConcurrentHashMap 是一个并发散列映射表 ... -
Hash散列及冲突解决
2012-07-17 17:56 2700先看看英文的维基百科上的解释: A hash func ... -
调用谷歌接口实现基站转经纬度
2012-07-02 15:34 6471Cell2GPSUtil.java,最近项目中用到的,记录一下 ... -
JSP动态显示服务器时间和客户端时间
2012-05-22 16:29 6344server-time.jsp内容如下: <%@ pa ... -
使用Spring3.0的AOP结合log4j实现接口方法执行时间记录
2012-05-18 14:30 6391项目使用RPC提供的内部服务,需要监控每个接口方法的调用情况以 ... -
禁止浏览器缓存当前文档内容
2011-06-08 17:21 1597IE8的设置中有这么一个选项: 默认是“自动 ... -
java正则匹配微博@和话题#话题#
2011-05-26 11:46 7909/** * 微博内容中的at正则表达式 ... -
restlet使用中遇到的一些问题
2011-02-22 17:37 18130x20 is not a legal NCName cha ... -
spring 2.5.6和hibernate3.2.2集成(5)
2010-02-08 15:48 1926这一次说一下hibernate tools这个工具的使用,OR ... -
spring 2.5.6和hibernate3.2.2集成(4)
2010-02-04 16:41 2714这个列子的来源是springside下的miniweb项目,算 ... -
spring 2.5.6和hibernate3.2.2集成(2)
2010-02-04 15:52 1284上一篇文章写了如何使用spring的注解,这一篇记录一下和hi ... -
spring 2.5.6和hibernate3.2.2集成(1)
2010-02-04 15:33 1247spring注解的使用,这个例子来源于网上,我也不知道原创是哪 ... -
The project was not built since the source file could not be read
2010-01-25 10:25 3776包缺失 重新加入JRE System Library 类 ... -
The hierarchy of the type is inconsistent
2010-01-22 10:02 14797这两天在尝试spring2.5.6和hibernate3.2的 ... -
activemq-5.3集成spring2.5以及quartz的调用
2010-01-06 10:42 1448前几天做的demo,记录一下,希望对大家有帮助,内容均参考网上 ... -
Dom4j的使用,存着以后看
2008-12-05 10:21 1070Dom4j的使用(全而好的文 ... -
JVM中的堆和栈
2007-12-29 16:19 2211JVM是基于堆栈的虚拟机. ... -
Struts2.0上传练习
2007-11-09 16:09 6737终于上次的项目告一段落了,可以重新学习Struts了,于是终于 ... -
struts2.0使用时的一个奇怪的问题
2007-10-21 22:31 1049近来struts2.0很流行哦,于是下了更流行的max大侠的教 ... -
DAO+Factory+Hibernate的学习。。
2007-09-30 16:48 3001看了很多的书了,想着实践一下,就参考了书上的例子写了一点,呵呵 ...
相关推荐
NULL 博文链接:https://willvvv.iteye.com/blog/587557
包含 Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2 整合的包。
一、Spring MVC环境搭建:(Spring 2.5.6 + Hibernate 3.2.0) 1. jar包引入 Spring 2.5.6:spring.jar、spring-webmvc.jar、commons-logging.jar、cglib-nodep-2.1_3.jar Hibernate 3.6.8:hibernate3.jar...
自己整理的struts1.3.8+spring2.5.6+hibernate3.3框架集成,项目带jar包,直接导入即可运行。
struts2.1.8.1+spring2.5.6+hibernate3.5.6整合注解,测试环境使用myeclipse2014,jdk6,javaee6
struts-2.3、spring2.5.6、hibernate3.3整合示例,源码,导入可运行
SSH项目整合,包含本项目所有的JAR包,基于mysql数据库,完成了基本的“增,删,改,查,完整分页”,另外做了一点js验证,以及建表,插入指定数量的随机测试数据...... 绝对值这个分。
Struts2.1.8+Spring2.5.6+hibernate3.2.3整合
spring2.5.6与hibernate3.3整合示例,导入即可运行。运用注解、hibernateTemplate、声明式事务管理。包括所有需要jar包。
Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解
spring2.5.6+hibernate3.3.2+struts2.1.8 初学者的整理的好帮手
struts2+spring2.5.6+hibernate3.0+ext
Struts2.1.6+Spring2.5.6+Hibernate3.3.1整合 步骤非常详细,每步都有说明!
struts2.1.8 + spring2.5.6 + hibernate3.3.2整合,可以看一下,比较完全
Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解 docx文档教程
Struts2.1.6+Spring2.5.6+Hibernate3.3.1框架整合常见错误.txt 初学者开发常见错误!
struts2.1.8+spring2.5.6+hibernate3.3.2整合项目开发 比较完整哦 可以作为模板的
struts2.2.3+spring2.5.6+hibernate3.2+proxool0.9.1 proxool数据库连接池例子 0资源下载
Struts2.1.6 Spring2.5.6 Hibernate3.3.2