- 浏览: 169157 次
- 性别:
- 来自: 广东
最新评论
-
pouyang:
感情很细腻。
她真的走了,昨天下午,走了,空荡荡的.... -
懒萝卜:
我也经常使用楼主的做法,
ModelDriven只有听说过,没 ...
是否应该用ModelDriven? -
zhengyutong:
很赞同楼主的说法。没有必要继承ModelDriven接口来实现 ...
是否应该用ModelDriven? -
wmj2003:
我答了很多遍!最后发现,如果答对了,robbin给的提示也太不 ...
我要给JavaEye喷口水 -
fisher126:
像你这样的用户不好伺候。
我要给JavaEye喷口水
我百思不得期解,在Spring2.0下可以,一到Spring2.5就不行了,请各位帮忙看看。
User.java
package spring25.ch06; public class User { private String id; private String name; private String comment; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } }
UserDao.java
package spring25.ch06; import java.util.List; public interface UserDao { void create(User user); void update(User user); public void delete(User user); public List<User> list(); }
UserDaoImpl.java
package spring25.ch06.hibernate; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.transaction.annotation.Transactional; import spring25.ch06.User; import spring25.ch06.UserDao; public class UserDaoImpl implements UserDao { private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Override @Transactional public void create(User user) { Session session = sessionFactory.getCurrentSession(); session.save(user); } @Override @Transactional public void update(User user) { Session session = sessionFactory.getCurrentSession(); session.update(user); } @Override @Transactional public void delete(User user) { Session session = sessionFactory.getCurrentSession(); session.delete(user); } @Override @SuppressWarnings("unchecked") @Transactional(readOnly=true) public List<User> list() { Session session = sessionFactory.getCurrentSession(); return session.createQuery("from User u").list(); } }
Main.java
package spring25.ch06.hibernate; import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import spring25.ch06.User; import spring25.ch06.UserDao; public class Main { private static UserDao userDao; static { ApplicationContext ctx = new ClassPathXmlApplicationContext("spring25/ch06/hibernate/config.xml"); userDao = (UserDao) ctx.getBean("userDao"); } public static void main(String[] args) throws Exception { listUsers(); User user = new User(); user.setName("juggler"); user.setComment("juggler is a good boy."); userDao.create(user); listUsers(); user.setName("magic"); userDao.update(user); listUsers(); user = new User(); user.setName("Kut"); user.setComment("He is a good programmer."); userDao.create(user); listUsers(); userDao.delete(user); listUsers(); } private static void listUsers() { List<User> users = userDao.list(); for (User u : users) { System.out.println("ID: " + u.getId()); System.out.println("Name: " + u.getName()); System.out.println("Comment: " + u.getComment()); System.out.println("---------------------------------"); } System.out.println("\n"); } }
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost/spring_study</property> <property name="connection.username">root</property> <property name="connection.password">xxxxxxx</property> <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="current_session_context_class">thread</property> <property name="show_sql">false</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.use_sql_comments">true</property> <mapping resource="spring25/ch06/User.hbm.xml" /> </session-factory> </hibernate-configuration>
User.hbm.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="spring25.ch06"> <class name="User" table="user" dynamic-update="true"> <id name="id" column="id"> <generator class="uuid" /> </id> <property name="name" type="string" column="name" /> <property name="comment" type="string" column="comment" /> </class> </hibernate-mapping>
config.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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:spring25/ch06/hibernate/hibernate.cfg.xml" /> </bean> <bean id="userDao" class="spring25.ch06.hibernate.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
运行出错:
Exception in thread "main" org.hibernate.HibernateException: createQuery is not valid without active transaction at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:297) at $Proxy7.createQuery(Unknown Source) at spring25.ch06.hibernate.UserDaoImpl.list(UserDaoImpl.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy5.list(Unknown Source) at spring25.ch06.hibernate.Main.listUsers(Main.java:44) at spring25.ch06.hibernate.Main.main(Main.java:20)
评论
12 楼
jiang117
2008-10-10
终于把spring2.5 的事务配好了,记录一下
<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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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">
上面红色标记的不能少,否侧会报如下错误,俺在网上找了好久,好多人都报这样的错,但就是没人回答,而且都是
E文的,自己终于摸索出来了,哈哈。。。。。。
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:advice'.
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
<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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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">
上面红色标记的不能少,否侧会报如下错误,俺在网上找了好久,好多人都报这样的错,但就是没人回答,而且都是
E文的,自己终于摸索出来了,哈哈。。。。。。
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:advice'.
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
11 楼
jiang117
2008-10-10
jiangzy 写道
错误信息:如下:
2008-1-21 19:40:55 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache Tomcat Native library which allows optimal performance in produ
ction environments was not found on the java.library.path: D:\WorkTools\JavaTool
s\JDK6\jdk1.6.0_03\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;
C:\Python\;C:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;D
:\WorkTools\JavaTools\JDK6\jdk1.6.0_03\bin ;C:\Program Files\Perforce;D:\WorkToo
ls\JavaTools\PHP5;C:\Program Files\SSH Communications Security\SSH Secure Shell
2008-1-21 19:40:55 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-1-21 19:40:55 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 574 ms
2008-1-21 19:40:55 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-1-21 19:40:55 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.14
2008-01-21 19:40:57,820 ERROR [org.springframework.web.context.ContextLoader] -
<Context initialization failed>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Config
uration problem: Failed to import bean definitions from relative location [sprin
g-xml/applicationContext-DB.xml]
Offending resource: class path resource [applicationContext.xml]; nested excepti
on is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
exception parsing XML document from class path resource [spring-xml/application
Context-DB.xml]; nested exception is java.lang.NoClassDefFoundError: org/aspectj
/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.parsing.FailFastProblemReporter.err
or(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderC
ontext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderC
ontext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:201)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:147)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:132)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registe
rBeanDefinitions(XmlBeanDefinitionReader.java:488)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:383)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:327)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:295)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.web.context.support.XmlWebApplicationContext.load
BeanDefinitions(XmlWebApplicationContext.java:124)
at org.springframework.web.context.support.XmlWebApplicationContext.load
BeanDefinitions(XmlWebApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationCon
text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97)
at org.springframework.context.support.AbstractApplicationContext.obtain
FreshBeanFactory(AbstractApplicationContext.java:411)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:338)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:261)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:45)
at com.common.util.LocalContextLoaderListener.contextInitialized(LocalCo
ntextLoaderListener.java:30)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3830)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
337)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:77
1)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443
)
at org.apache.catalina.core.StandardService.start(StandardService.java:5
16)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexp
ected exception parsing XML document from class path resource [spring-xml/applic
ationContext-DB.xml]; nested exception is java.lang.NoClassDefFoundError: org/as
pectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:405)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:327)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:295)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:190)
... 43 more
Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/Reflection
World$ReflectionWorldException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.springframework.aop.config.ConfigBeanDefinitionParser.class$(Conf
igBeanDefinitionParser.java:209)
at org.springframework.aop.config.ConfigBeanDefinitionParser.createPoint
cutDefinition(ConfigBeanDefinitionParser.java:535)
at org.springframework.aop.config.ConfigBeanDefinitionParser.parsePointc
utProperty(ConfigBeanDefinitionParser.java:509)
at org.springframework.aop.config.ConfigBeanDefinitionParser.parseAdviso
r(ConfigBeanDefinitionParser.java:187)
at org.springframework.aop.config.ConfigBeanDefinitionParser.parse(Confi
gBeanDefinitionParser.java:146)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(N
amespaceHandlerSupport.java:69)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.pa
rseCustomElement(BeanDefinitionParserDelegate.java:1246)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.pa
rseCustomElement(BeanDefinitionParserDelegate.java:1236)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registe
rBeanDefinitions(XmlBeanDefinitionReader.java:488)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:383)
... 46 more
2008-1-21 19:40:57 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2008-1-21 19:40:57 org.apache.catalina.core.StandardContext start
严重: Context [/xmweb] startup failed due to previous errors
2008-1-21 19:40:58 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2008-1-21 19:40:58 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2008-1-21 19:40:58 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/47 config=null
2008-1-21 19:40:58 org.apache.catalina.startup.Catalina start
信息: Server startup in 3123 ms
你这个错误是少了一个包:aspectjweaver.jar 到spring2.5原包下面去找
10 楼
晨星★~雨泪
2008-09-14
java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
这个没有,加上他的依赖包,试试
这个没有,加上他的依赖包,试试
9 楼
lirig
2008-09-12
最好把背景换下
哈哈!
哈哈!
8 楼
Frederick
2008-03-28
我也遇到了类似的问题。不过我使用的持久层不是hibernate,而是db4o,配置也不是传统的xml,而是使用annotation。但是问题是类似的,写入数据库的数据没能找到,估计是事务失败了导致的。
我遇到的问题是,系统初始化的时候,王数据库里面写入了一些数据。然后在后面使用这些数据的时候,发现无法在数据库里面找到这些数据。系统没有报错,估计是初始化的时候事务没有提交
我遇到的问题是,系统初始化的时候,王数据库里面写入了一些数据。然后在后面使用这些数据的时候,发现无法在数据库里面找到这些数据。系统没有报错,估计是初始化的时候事务没有提交
7 楼
jiangzy
2008-01-21
Spring.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Middle tier application context definition for the image database.
-->
<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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:resources/pool/proxool.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.logicalcobwebs.proxool.ProxoolDataSource"
destroy-method="close">
<property name="driver">
<value>${proxool.drivername}</value>
</property>
<property name="driverUrl">
<value>${proxool.url}</value>
</property>
<property name="user">
<value>${proxool.username}</value>
</property>
<property name="password">
<value>${proxool.password}</value>
</property>
<property name="alias">
<value>${proxool.alias}</value>
</property>
<property name="houseKeepingSleepTime">
<value>${proxool.hourseKeepingSleepTime}</value>
</property>
<property name="prototypeCount">
<value>${proxool.prototypeCount}</value>
</property>
<property name="maximumConnectionCount">
<value>${proxool.maximumConnectionCount}</value>
</property>
<property name="minimumConnectionCount">
<value>${proxool.minimumConnectionCount}</value>
</property>
<property name="trace">
<value>${proxool.trace}</value>
</property>
<property name="verbose">
<value>${proxool.verbose}</value>
</property>
<property name="houseKeepingTestSql">
<value>${proxool.houseKeepingTestSql}</value>
</property>
<property name="delegateProperties"
value="user=${proxool.username},password=${proxool.password}" />
</bean>
<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.postgresql.Driver">
</property>
<property name="url"
value="jdbc:postgresql://localhost:5432/xmweb">
</property>
<property name="username" value="xmleo"></property>
<property name="password" value="123456"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</prop>
<prop key="hibernate.connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.proxool.existing_pool">true</prop>
<!-- 把所有的SQL语句都输出到控制台 。true:输出到控制台-->
<prop key="hibernate.show_sql">true</prop>
<!-- Fetch Size 是设定JDBC的Statement读取数据的时候每次从数据库中取出的记录条数,我建议使用Oracle的最好将Fetch Size设到50-->
<prop key="hibernate.jdbc.fetch_size">50</prop>
<!-- atch Size是设定对数据库进行批量删除,批量更新和批量插入的时候的批次大小,我建议使用Oracle的最好将Batch Size设到30~50-->
<prop key="hibernate.jdbc.batch_size">30</prop>
<!-- 默认打开,启用cglib反射优化。cglib是用来在Hibernate中动态生成PO字节码的,打开优化可以加快字节码构造的速度 false:调试状态是最好关闭
-->
<prop key="hibernate.cglib.use_reflection_optimizer">
true
</prop>
<!-- 在SessionFactory创建后,自动输出schema创建DDL语句到数据库.和create-drop同时使用的话,数据库schema会在SessionFactory显式关闭后被drop掉。 -->
<!-- prop key="hibernate.hbm2ddl.auto">update</prop--><!--update validate-->
<!--数据库连接池,proxool 启动选项 -->
<!--<prop key="hibernate.proxool.xml">proxool.xml</prop> -->
<!--数据库连接池,proxool别名 -->
<!-- <prop key="hibernate.proxool.pool_alias">proxool</prop>-->
</props>
</property>
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!--事务 -->
<bean id="txManager" abstract="true"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config proxy-target-class="true">
<aop:advisor
pointcut="execution(* com.xm.application.business.impl.*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"
rollback-for="Exception" />
<tx:method name="find*" read-only="true"
rollback-for="Exception" />
<tx:method name="load*" read-only="true"
rollback-for="Exception" />
<tx:method name="save*" read-only="false" />
<tx:method name="insert*" no-rollback-for="Exception" />
<tx:method name="remove*" />
<tx:method name="add*" no-rollback-for="Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 支持 @Transactional 标记
<tx:annotation-driven />
支持 @AspectJ 标记
<aop:aspectj-autoproxy/>-->
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref local="dataSource"></ref>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory"></ref>
</property>
</bean>
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
abstract="false" scope="singleton" lazy-init="true" autowire="default"
dependency-check="default">
</bean>
<bean id="lobHandler"
class="org.springframework.jdbc.support.lob.OracleLobHandler"
lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor" />
</property>
</bean>
<!--
ehcache缓存管理器.
-->
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation"
value="classpath:resources/cache/ehcache.xml" />
<property name="shared" value="true" />
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Middle tier application context definition for the image database.
-->
<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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:resources/pool/proxool.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.logicalcobwebs.proxool.ProxoolDataSource"
destroy-method="close">
<property name="driver">
<value>${proxool.drivername}</value>
</property>
<property name="driverUrl">
<value>${proxool.url}</value>
</property>
<property name="user">
<value>${proxool.username}</value>
</property>
<property name="password">
<value>${proxool.password}</value>
</property>
<property name="alias">
<value>${proxool.alias}</value>
</property>
<property name="houseKeepingSleepTime">
<value>${proxool.hourseKeepingSleepTime}</value>
</property>
<property name="prototypeCount">
<value>${proxool.prototypeCount}</value>
</property>
<property name="maximumConnectionCount">
<value>${proxool.maximumConnectionCount}</value>
</property>
<property name="minimumConnectionCount">
<value>${proxool.minimumConnectionCount}</value>
</property>
<property name="trace">
<value>${proxool.trace}</value>
</property>
<property name="verbose">
<value>${proxool.verbose}</value>
</property>
<property name="houseKeepingTestSql">
<value>${proxool.houseKeepingTestSql}</value>
</property>
<property name="delegateProperties"
value="user=${proxool.username},password=${proxool.password}" />
</bean>
<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.postgresql.Driver">
</property>
<property name="url"
value="jdbc:postgresql://localhost:5432/xmweb">
</property>
<property name="username" value="xmleo"></property>
<property name="password" value="123456"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</prop>
<prop key="hibernate.connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.proxool.existing_pool">true</prop>
<!-- 把所有的SQL语句都输出到控制台 。true:输出到控制台-->
<prop key="hibernate.show_sql">true</prop>
<!-- Fetch Size 是设定JDBC的Statement读取数据的时候每次从数据库中取出的记录条数,我建议使用Oracle的最好将Fetch Size设到50-->
<prop key="hibernate.jdbc.fetch_size">50</prop>
<!-- atch Size是设定对数据库进行批量删除,批量更新和批量插入的时候的批次大小,我建议使用Oracle的最好将Batch Size设到30~50-->
<prop key="hibernate.jdbc.batch_size">30</prop>
<!-- 默认打开,启用cglib反射优化。cglib是用来在Hibernate中动态生成PO字节码的,打开优化可以加快字节码构造的速度 false:调试状态是最好关闭
-->
<prop key="hibernate.cglib.use_reflection_optimizer">
true
</prop>
<!-- 在SessionFactory创建后,自动输出schema创建DDL语句到数据库.和create-drop同时使用的话,数据库schema会在SessionFactory显式关闭后被drop掉。 -->
<!-- prop key="hibernate.hbm2ddl.auto">update</prop--><!--update validate-->
<!--数据库连接池,proxool 启动选项 -->
<!--<prop key="hibernate.proxool.xml">proxool.xml</prop> -->
<!--数据库连接池,proxool别名 -->
<!-- <prop key="hibernate.proxool.pool_alias">proxool</prop>-->
</props>
</property>
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!--事务 -->
<bean id="txManager" abstract="true"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config proxy-target-class="true">
<aop:advisor
pointcut="execution(* com.xm.application.business.impl.*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"
rollback-for="Exception" />
<tx:method name="find*" read-only="true"
rollback-for="Exception" />
<tx:method name="load*" read-only="true"
rollback-for="Exception" />
<tx:method name="save*" read-only="false" />
<tx:method name="insert*" no-rollback-for="Exception" />
<tx:method name="remove*" />
<tx:method name="add*" no-rollback-for="Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 支持 @Transactional 标记
<tx:annotation-driven />
支持 @AspectJ 标记
<aop:aspectj-autoproxy/>-->
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref local="dataSource"></ref>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory"></ref>
</property>
</bean>
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
abstract="false" scope="singleton" lazy-init="true" autowire="default"
dependency-check="default">
</bean>
<bean id="lobHandler"
class="org.springframework.jdbc.support.lob.OracleLobHandler"
lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor" />
</property>
</bean>
<!--
ehcache缓存管理器.
-->
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation"
value="classpath:resources/cache/ehcache.xml" />
<property name="shared" value="true" />
</bean>
</beans>
6 楼
jiangzy
2008-01-21
错误信息:如下:
2008-1-21 19:40:55 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache Tomcat Native library which allows optimal performance in produ
ction environments was not found on the java.library.path: D:\WorkTools\JavaTool
s\JDK6\jdk1.6.0_03\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;
C:\Python\;C:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;D
:\WorkTools\JavaTools\JDK6\jdk1.6.0_03\bin ;C:\Program Files\Perforce;D:\WorkToo
ls\JavaTools\PHP5;C:\Program Files\SSH Communications Security\SSH Secure Shell
2008-1-21 19:40:55 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-1-21 19:40:55 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 574 ms
2008-1-21 19:40:55 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-1-21 19:40:55 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.14
2008-01-21 19:40:57,820 ERROR [org.springframework.web.context.ContextLoader] -
<Context initialization failed>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Config
uration problem: Failed to import bean definitions from relative location [sprin
g-xml/applicationContext-DB.xml]
Offending resource: class path resource [applicationContext.xml]; nested excepti
on is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
exception parsing XML document from class path resource [spring-xml/application
Context-DB.xml]; nested exception is java.lang.NoClassDefFoundError: org/aspectj
/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.parsing.FailFastProblemReporter.err
or(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderC
ontext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderC
ontext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:201)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:147)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:132)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registe
rBeanDefinitions(XmlBeanDefinitionReader.java:488)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:383)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:327)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:295)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.web.context.support.XmlWebApplicationContext.load
BeanDefinitions(XmlWebApplicationContext.java:124)
at org.springframework.web.context.support.XmlWebApplicationContext.load
BeanDefinitions(XmlWebApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationCon
text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97)
at org.springframework.context.support.AbstractApplicationContext.obtain
FreshBeanFactory(AbstractApplicationContext.java:411)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:338)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:261)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:45)
at com.common.util.LocalContextLoaderListener.contextInitialized(LocalCo
ntextLoaderListener.java:30)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3830)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
337)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:77
1)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443
)
at org.apache.catalina.core.StandardService.start(StandardService.java:5
16)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexp
ected exception parsing XML document from class path resource [spring-xml/applic
ationContext-DB.xml]; nested exception is java.lang.NoClassDefFoundError: org/as
pectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:405)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:327)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:295)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:190)
... 43 more
Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/Reflection
World$ReflectionWorldException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.springframework.aop.config.ConfigBeanDefinitionParser.class$(Conf
igBeanDefinitionParser.java:209)
at org.springframework.aop.config.ConfigBeanDefinitionParser.createPoint
cutDefinition(ConfigBeanDefinitionParser.java:535)
at org.springframework.aop.config.ConfigBeanDefinitionParser.parsePointc
utProperty(ConfigBeanDefinitionParser.java:509)
at org.springframework.aop.config.ConfigBeanDefinitionParser.parseAdviso
r(ConfigBeanDefinitionParser.java:187)
at org.springframework.aop.config.ConfigBeanDefinitionParser.parse(Confi
gBeanDefinitionParser.java:146)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(N
amespaceHandlerSupport.java:69)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.pa
rseCustomElement(BeanDefinitionParserDelegate.java:1246)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.pa
rseCustomElement(BeanDefinitionParserDelegate.java:1236)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registe
rBeanDefinitions(XmlBeanDefinitionReader.java:488)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:383)
... 46 more
2008-1-21 19:40:57 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2008-1-21 19:40:57 org.apache.catalina.core.StandardContext start
严重: Context [/xmweb] startup failed due to previous errors
2008-1-21 19:40:58 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2008-1-21 19:40:58 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2008-1-21 19:40:58 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/47 config=null
2008-1-21 19:40:58 org.apache.catalina.startup.Catalina start
信息: Server startup in 3123 ms
5 楼
jiangzy
2008-01-21
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.jhtl.service..*.save(..))" advice-ref="txAdvice"/>
</aop:config>
我加了上面的
<aop:config proxy-target-class="true">
会出问题,是不是哪个包没有引入的,我用的也是SPRING2.5
<aop:advisor pointcut="execution(* com.jhtl.service..*.save(..))" advice-ref="txAdvice"/>
</aop:config>
我加了上面的
<aop:config proxy-target-class="true">
会出问题,是不是哪个包没有引入的,我用的也是SPRING2.5
4 楼
xujianxie
2008-01-16
<?xml version="1.0" encoding="GBK"?> <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-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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/classes/proxool.properties</value> </property> </bean> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"> <property name="driver"> <value>${proxool.driver}</value> </property> <property name="driverUrl"> <value>${proxool.url}</value> </property> <property name="user"> <value>${proxool.username}</value> </property> <property name="password"> <value>${proxool.password}</value> </property> <property name="alias"> <value>${proxool.alias}</value> </property> <property name="houseKeepingSleepTime"> <value>${proxool.houseKeepingSleepTime}</value> </property> <property name="prototypeCount"> <value>${proxool.prototypeCount}</value> </property> <property name="maximumConnectionCount"> <value>${proxool.maximumConnectionCount}</value> </property> <property name="minimumConnectionCount"> <value>${proxool.minimumConnectionCount}</value> </property> <property name="trace"> <value>${proxool.trace}</value> </property> <property name="verbose"> <value>${proxool.verbose}</value> </property> <property name="houseKeepingTestSql"> <value>${proxool.houseKeepingTestSql}</value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name="dataSource"> <ref local="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> <!-- oracle org.hibernate.dialect.Oracle10gDialect --> org.hibernate.dialect.MySQLInnoDBDialect </prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingLocations"> <list> <value>classpath*:com/jhlt/model/*.hbm.xml</value> </list> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" rollback-for="Exception" /> <tx:method name="save*" read-only="false"/> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.jhlt.service.*.*(..))" advice-ref="txAdvice"/> </aop:config> <bean id="courseDao" class="com.jhlt.dao.CourseDao"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="courseService" class="com.jhlt.service.CourseService"> <property name="courseDao"> <ref bean="courseDao"/> </property> </bean> </beans>哈哈,终于成功配置事务了哦
3 楼
xujianxie
2008-01-16
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name="dataSource"> <ref local="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect </prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingLocations"> <list> <value>classpath*:com/jhlt/model/*.hbm.xml</value> </list> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" rollback-for="Exception" /> <tx:method name="save*" read-only="false"/> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.jhtl.service..*.save(..))" advice-ref="txAdvice"/> </aop:config> <bean id="courseDao" class="com.jhlt.dao.CourseDao"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="courseService" class="com.jhlt.service.CourseService"> <property name="courseDao"> <ref bean="courseDao"/> </property> </bean>
我这个配置不会出错,但事务好像不起左右,失败了也不会回滚
2 楼
xujianxie
2008-01-16
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<value>classpath*:com/jhlt/model/*.hbm.xml</value>
</list>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" rollback-for="Exception" />
<tx:method name="save*" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.jhtl.service..*.save(..))" advice-ref="txAdvice"/>
</aop:config>
<bean id="courseDao"
class="com.jhlt.dao.CourseDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="courseService"
class="com.jhlt.service.CourseService">
<property name="courseDao">
<ref bean="courseDao"/>
</property>
</bean>
我这个配置不会出错,但事务没用,总是提交的,有错误不会回滚
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<value>classpath*:com/jhlt/model/*.hbm.xml</value>
</list>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" rollback-for="Exception" />
<tx:method name="save*" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.jhtl.service..*.save(..))" advice-ref="txAdvice"/>
</aop:config>
<bean id="courseDao"
class="com.jhlt.dao.CourseDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="courseService"
class="com.jhlt.service.CourseService">
<property name="courseDao">
<ref bean="courseDao"/>
</property>
</bean>
我这个配置不会出错,但事务没用,总是提交的,有错误不会回滚
1 楼
hamburg
2008-01-03
spring已经提供了所有增、删、改、查的实现,只要到继承这个类即可org.springframework.orm.hibernate.support.HibernateDaoSupport
Session session = sessionFactory.getCurrentSession();
如果是使用spring 干嘛要这样得到session
这个方法更好一些getSession();
相关推荐
Hibernate 3.2.5 GA 的使用参考手册,帮助开发者理解如何配置Hibernate,如设置实体类、映射文件、属性文件,以及如何在项目中整合Spring等其他框架。手册中还会涵盖最佳实践、性能优化和常见问题解答,是开发者...
《深入理解Hibernate 3.2.5GA:构建高效持久化解决方案》 Hibernate,作为一款强大的对象关系映射(ORM)框架,自诞生以来就深受Java开发者喜爱。本篇文章将聚焦于Hibernate 3.2.5GA版本,该版本包含了完整的源代码...
本框架选用的技术struts2.0.11,hibernate3.2.5ga,spring-framework-2.5,oracle92,少量采用ext-2.0脚本技术,IDE-myeclipse601 部署时,可修改web-inf/config/spring/applicationContext.xml文件,修改相应的数据库信息...
7. **Hibernate**: 可通过[http://jaist.dl.sourceforge.net/sourceforge/hibernate/hibernate-3.2.5.ga.zip](http://jaist.dl.sourceforge.net/sourceforge/hibernate/hibernate-3.2.5.ga.zip)下载。推荐使用...
7. **Hibernate**: Hibernate框架用于实现ORM(对象关系映射),可以在[这里](http://jaist.dl.sourceforge.net/sourceforge/hibernate/hibernate-3.2.5.ga.zip)下载3.2.5版本。 8. **Hibernate Synchronizer ...
9. **javassist-3.15.0-GA.jar**:Java编程辅助工具,提供运行时修改字节码的功能,被Hibernate和某些AOP框架如AspectJ使用。 10. **spring-web-3.2.5.RELEASE.jar**:Spring Web模块,提供了Web应用程序的特定功能...
SSH框架是Java开发中常用的三大框架整合,包括Spring、Struts2和Hibernate。这个压缩包提供了这些框架所需的所有jar包,且确保了无包冲突,方便开发者快速搭建项目环境。 首先,Spring框架是核心,其主要职责是管理...
`hibernate-3.2.5.ga-why.jar`是Hibernate 3的一个版本,它支持实体类与数据库表之间的映射,提供了事务管理、缓存机制、查询语言HQL等特性。 3. **Spring**:Spring是一个全面的Java企业级应用框架,强调依赖注入...
1. **hibernate-3.2.5.ga.jar**:这是Hibernate ORM框架的一个版本,用于将Java对象与关系数据库进行映射,实现对象关系映射。笔记可能讨论了如何通过DWR调用Hibernate服务,实现前后端数据的交互。 2. **spring....
hibernate-validator-4.2.0.Final.jar hsqldb-1.7.1.jar htmlunit-1.9.jar httpclient-4.0.1.jar httpclient-4.1.2.jar httpclient-4.2.5.jar httpclient-4.4.jar httpcore-4.0.1.jar httpcore-4.1.2.jar jackson-...