如何使用事务注释来捕获错误?

我使用Spring Boot 2.2。

在具有事务处理的方法中,如果没有错误,则通过存储库进行保存时,我想使用Rabbit mq发送消息。

如何确保存储库没有错误?


Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Original error: unexpected end of stream on Connection{127.0.0.1:4723,proxy=DIRECT hostAddress=/127.0.0.1:4723 cipherSuite=none protocol=http/1.1}

Build info: version: '3.141.59',revision: 'e82be7d358',time: '2018-11-14T08:17:03'

System info: host: 'C02Z53KELVCF',ip: 'fe80:0:0:0:4d1:face:6ad2:ee7a%en0',os.name: 'Mac OS X',os.arch: 'x86_64',os.version: '10.14.5',java.version: '1.8.0_191'

Driver info: driver.version: IOSDriver

Driver info: driver.version: IOSDriver

  at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)

  at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)

  at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)

  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)

  at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)

  at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)

  at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)

  at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)

  at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)

  at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)

  at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)

 at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)

  at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:95)

  at com.netspend.ns_tester.Selenium.DriverHandler.getLocalDriver(DriverHandler.groovy:193)

  ... 22 more

Caused by: java.lang.reflect.invocationTargetException

  at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)

  ... 35 more

Caused by: java.io.IOException: unexpected end of stream on Connection{127.0.0.1:4723,proxy=DIRECT hostAddress=/127.0.0.1:4723 cipherSuite=none protocol=http/1.1}

  at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208)

  at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

  at org.openqa.selenium.remote.internal.OkHttpClient$Factory$1.lambda$createclient$1(OkHttpClient.java:152)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

  at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

  at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)

 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

  at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)

 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)

  at okhttp3.RealCall.execute(RealCall.java:77)

  at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)

  at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)

  ... 36 more

Caused by: java.io.EOFException: \n not found: limit=0 content=…

  at okio.RealBufferedSource.readUtf8Linestrict(RealBufferedSource.java:237)

  at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)

  at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)

  ... 56 more

如果发送消息时出现错误,我不想回滚保存操作。

a840866712 回答:如何使用事务注释来捕获错误?

尽管它是Transactional和JPA,但它仍然是一种Java方法,如果保存失败,则将引发未经检查的DataAccessException异常,并且流程将不会继续发送消息。

  

类是运行时异常,如果认为任何错误是致命的(通常情况),则无需用户代码捕获它或子类。

,
    @Transactional
    public void save(CreditEvent creditEvent) {
      try {    
        repository.save(creditEvent);
        //no error send message}
      catch {
        // send message 
        // rethrow error 
      }
    }
本文链接:https://www.f2er.com/3013903.html

大家都在问