xiechunmei13
xiechunmei13
2009-09-01 21:04
浏览 363
已采纳

spring2.5事务注解

用到的是spring2.5的注解方式配置事务。
在接口中加入@Transactional这个就会报错,否则正常。
配置文件。
[code="java"]<?xml version="1.0" encoding="UTF-8" ?>
xmlns:aop="http://www.springframework.org/schema/aop" 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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<bean id="db-properties"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:ignoreUnresolvablePlaceholders="true">

    <property name="locations">
        <list>
            <value>classpath:DataBase.properties
            </value>
        </list>
    </property>
</bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 配置同一个数据源 -->  





<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName">
        <value>${db.driver}</value>
    </property>
    <property name="url">
        <value>${db.url}</value>
    </property>
    <property name="username">
        <value>${db.username}</value>
    </property>
    <property name="password">
        <value>${db.password}</value>
    </property>
    <property name="initialSize">
        <value>${db.pool.initial}</value>
    </property>
    <property name="maxActive">
        <value>${db.pool.max}</value>
    </property>
    <property name="defaultAutoCommit" value="false" />
</bean>
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
    p:dataSource-ref="dataSource" />



<bean id="threadPoolTaskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="2" />
    <property name="keepAliveSeconds" value="200" />
    <property name="maxPoolSize" value="10" />
    <property name="queueCapacity" value="60" />
</bean>

<bean id="transactionTemplate"
    class="org.springframework.transaction.support.TransactionTemplate">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
</bean>

[/code]

接口代码:
[code="java"]

import javax.jws.WebService;
import javax.ws.rs.core.Response;

import org.springframework.transaction.annotation.Transactional;

import com.sns.bestv.entity.VisFclass;
import com.sns.bestv.service.impl.VisFclassServiceImpl.Fclasses;

@WebService
@Transactional
public interface VisFclassService {
Response save(VisFclass fclass);
Response delete(String app_key,int cid,String groupsids);
Response update(VisFclass fclass);
Fclasses get(String app_key,int cid);
}

[/code]

启动时候控制台错误信息:
[code="java"]
2009-9-1 20:57:07 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:\java\jdk1.6.0_13\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;E:\java\jdk1.6.0_13\jre\bin;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.6.0_13\BIN;C:\Program Files\Common Files\Adobe\AGL;;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\TortoiseSVN\bin;D:\;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;d:\Program Files\SSH Secure Shell;C:\Program Files\SSH Communications Security\SSH Secure Shell
2009-9-1 20:57:07 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8081
2009-9-1 20:57:07 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 763 ms
2009-9-1 20:57:07 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2009-9-1 20:57:07 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.18
log4j:ERROR Parsing error on line 30 and column 23
log4j:ERROR The content of element type "log4j:configuration" must match "(renderer*,appender*,(category|logger)*,root?,categoryFactory?)".
2009-9-1 20:57:08 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
20:57:08,359 INFO org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189):
Root WebApplicationContext: initialization started
20:57:08,437 INFO org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:411):
Refreshing org.springframework.web.context.support.XmlWebApplicationContext@db95a1: display name [Root WebApplicationContext]; startup date [Tue Sep 01 20:57:08 CST 2009]; root of context hierarchy
20:57:08,609 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323):
Loading XML bean definitions from class path resource [applicationContext.xml]
20:57:08,937 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323):
Loading XML bean definitions from class path resource [serviceContext.xml]
20:57:09,000 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323):
Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
20:57:09,046 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323):
Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-soap.xml]
20:57:09,093 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323):
Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]
20:57:09,187 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323):
Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-jaxrs-binding.xml]
20:57:09,296 INFO org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:426):
Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@db95a1]: org.springframework.beans.factory.support.DefaultListableBeanFactory@138847d
20:57:09,671 INFO org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:178):
Loading properties file from class path resource [DataBase.properties]
20:57:10,000 INFO org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:414):
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@138847d: defining beans [db-properties,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,daoTemplate,dataSource,transactionManager,userDao,customerDao,custUserDao,aipUsersDao,aipLogDao,postDao,friendDao,messageDao,fclassDao,userClassDao,customizeDao,threadPoolTaskExecutor,transactionTemplate,cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,org.apache.cxf.jaxrs.JAXRSBindingFactory,userServices,profileService,postService,friendService,messageService,groupService,custermerService,customizeService,userServices_wa]; root of factory hierarchy
20:57:10,500 INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.initialize(ThreadPoolTaskExecutor.java:250):
Initializing ThreadPoolExecutor 'threadPoolTaskExecutor'
2009-9-1 20:57:12 org.apache.cxf.jaxrs.utils.InjectionUtils reportServerError
严重: Method setMessageContext injection failure
20:57:12,968 INFO org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:421):
Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@138847d: defining beans [db-properties,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,daoTemplate,dataSource,transactionManager,userDao,customerDao,custUserDao,aipUsersDao,aipLogDao,postDao,friendDao,messageDao,fclassDao,userClassDao,customizeDao,threadPoolTaskExecutor,transactionTemplate,cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,org.apache.cxf.jaxrs.JAXRSBindingFactory,userServices,profileService,postService,friendService,messageService,groupService,custermerService,customizeService,userServices_wa]; root of factory hierarchy
20:57:12,984 INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.shutdown(ThreadPoolTaskExecutor.java:349):
Shutting down ThreadPoolExecutor 'threadPoolTaskExecutor'
20:57:12,984 ERROR org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215):
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices_wa': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
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:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:112)
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.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more
Caused by: javax.ws.rs.WebApplicationException
at org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:277)
at org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:190)
at org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxies(InjectionUtils.java:656)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:180)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:201)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:81)
... 37 more
2009-9-1 20:57:13 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices_wa': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
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:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:112)
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.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more
Caused by: javax.ws.rs.WebApplicationException
at org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:277)
at org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:190)
at org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxies(InjectionUtils.java:656)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:180)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:201)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:81)
... 37 more
2009-9-1 20:57:13 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2009-9-1 20:57:13 org.apache.catalina.core.StandardContext start
严重: Context [] startup failed due to previous errors
2009-9-1 20:57:13 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2009-9-1 20:57:13 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8081
2009-9-1 20:57:13 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:9009
2009-9-1 20:57:13 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/47 config=null
2009-9-1 20:57:13 org.apache.catalina.startup.Catalina start
信息: Server startup in 6270 ms

[/code]
[b]问题补充:[/b]
1:@Transactional 不是说用注解就得用接口吗?你说的加到实现类上我也试了一样的错误。
2:[code="java"] class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">









[/code]
这是连接池的东西。
3: <!-- 定义切入点,引用事务通知 -->
[code="java"]
pointcut="execution (* com.mobile.dao.*.*(..))"/>[/code] /aop:config
这种方式我试过了。也会出错。
[b]4:其二,既然你要用注解的方式,那么你就要在你的项目中,加入这两个jar包:aspectjweaver.jar aspectjrt.jar
我好像没加这两个包。我加加试试。[/b]
5:配置文件哪里有问题?如果我不在接口或类上加@Transactional 就是完全正确的运行。
谢谢!请帮忙!
[b]问题补充:[/b]
[b]再补充:两个包我加了,还是一样的错误。而且那两个包是aop才需要的吧?[/b]
[b]问题补充:[/b]
[b][color=darkred]yangtao309[/color][/b]
按照你说的把那个多余的连接池delete了。程序不会出错了。
但是不会回滚事务?
那我另问一下:[color=blue]我把@Transactional(readOnly=false)
public Response addCustomer(VisCustomer cut)
放在一个接口的实现类的方法上面,那是不是就说我这个方法体都具有一个相同的事务呢?只要其中一个地方出错整个方法都执行失败?
因为我这个方法内不止使用了一个dao的一个方法,有多个方法。比如我现在有 table1,table1-2(关系表),table2
我现在要操作table1,给其insert ,insert之后要向 table1-2中添加一条数据,这时我添加table1-2时出错了,那么我操作table1的数据可以回滚吗?
[/color]
[b]问题补充:[/b]
[b]我添加table1-2时并没有异常,是在数据库中被回滚的,程序中执行是正确的。这样能把它在程序中就回滚了吗?我正在看spring2.5的开发参考手册,其中rollbackForClassname 是定义一组类的名字,必须是Throwable的子类,遇到时必须回滚。如果我产生不了异常不就是说还是回滚不了?[/b]
[b]问题补充:[/b]
[quote]@Transactional(readOnly=false,rollbackFor = Throwable.class)[/quote]
不能回滚事务。肯定还有地方不对。但是配置我想是没问题了。看了api现在完全按照上面来了。非常非常感谢[color=olive]yangtao309 [/color]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • samungtered
    samungtered 2009-09-02 09:51
    已采纳

    你已经 配置了dbcp的数据源

    还需要配置连接池吗?

    建议你:
    先一步步来 检测
    不要一下子加那么多配置文件

    先把这个所谓的配置连接池的干掉
    单纯的配置个事物 看能否成功
    一个个加进来 才是正统的方法
    一下子加那么多 错误很多在一起 根本就分辨不了

    点赞 评论
  • samungtered
    samungtered 2009-09-01 21:33

    [quote]@Transactional [/quote]
    应该标注在实现类上面吧

    [quote] class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">









    [/quote]

    这个你 是配置的什么呢?

    总之你配置的时候 一步步来
    不要一下子加那么多的配置

    从最简单的 配置事务开始 用传统方式 或者AOP方式
    然后在具体实现类上加事务的注解@Transactional
    或者是其方法上加
    然后在其类的方法里面设置断点
    看事物进来没啊

    点赞 评论
  • walsh_bupt
    walsh_bupt 2009-09-01 23:35

    把你的@Transactional 放在具体的实现类上,不要放在接口上。

    其二,既然你要用注解的方式,那么你就要在你的项目中,加入这两个jar包:aspectjweaver.jar aspectjrt.jar

    其三:你的Spring配置文件写的就有问题:

    点赞 评论
  • samungtered
    samungtered 2009-09-02 10:32

    [quote]我把@Transactional(readOnly=false)
    public Response addCustomer(VisCustomer cut)
    放在一个接口的实现类的方法上面,那是不是就说我这个方法体都具有一个相同的事务呢?只要其中一个地方出错整个方法都执行失败?
    因为我这个方法内不止使用了一个dao的一个方法,有多个方法。比如我现在有 table1,table1-2(关系表),table2
    我现在要操作table1,给其insert ,insert之后要向 table1-2中添加一条数据,这时我添加table1-2时出错了,那么我操作table1的数据可以回滚吗?[/quote]

    对于你加的事物
    定义在类上面得事物@Transactional会给最全的事物级别
    然后还可以在每个方法上特殊定义其不同

    你操作的表间插入数据问题,
    定义在一个IMPL方法里的 肯定是能够回滚

    你可以试下 这方面建议你参考springFreamwork 2.5的手册 上面有详细说明

    点赞 评论

相关推荐