|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.support.AopUtils; |
|
|
|
import org.springframework.aop.support.AopUtils; |
|
|
|
import org.springframework.beans.factory.BeanCreationException; |
|
|
|
import org.springframework.beans.factory.BeanCreationException; |
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
|
|
@ -55,13 +56,14 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { |
|
|
|
Assume.group(TestGroup.PERFORMANCE); |
|
|
|
Assume.group(TestGroup.PERFORMANCE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void failsWhenJdkProxyAndScheduledMethodNotPresentOnInterface() { |
|
|
|
public void failsWhenJdkProxyAndScheduledMethodNotPresentOnInterface() { |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class); |
|
|
|
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
ctx.refresh(); |
|
|
|
ctx.refresh(); |
|
|
|
fail("expected exception"); |
|
|
|
fail("Should have thrown BeanCreationException"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
assertTrue(ex.getRootCause().getMessage().startsWith("@Scheduled method 'scheduled' found")); |
|
|
|
assertTrue(ex.getRootCause().getMessage().startsWith("@Scheduled method 'scheduled' found")); |
|
|
|
@ -101,28 +103,36 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableTransactionManagement |
|
|
|
@EnableTransactionManagement |
|
|
|
static class JdkProxyTxConfig { } |
|
|
|
static class JdkProxyTxConfig { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableTransactionManagement(proxyTargetClass=true) |
|
|
|
@EnableTransactionManagement(proxyTargetClass=true) |
|
|
|
static class SubclassProxyTxConfig { } |
|
|
|
static class SubclassProxyTxConfig { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
static class RepoConfigA { |
|
|
|
static class RepoConfigA { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public MyRepository repository() { |
|
|
|
public MyRepository repository() { |
|
|
|
return new MyRepositoryImpl(); |
|
|
|
return new MyRepositoryImpl(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
static class RepoConfigB { |
|
|
|
static class RepoConfigB { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public MyRepositoryWithScheduledMethod repository() { |
|
|
|
public MyRepositoryWithScheduledMethod repository() { |
|
|
|
return new MyRepositoryWithScheduledMethodImpl(); |
|
|
|
return new MyRepositoryWithScheduledMethodImpl(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableScheduling |
|
|
|
@EnableScheduling |
|
|
|
static class Config { |
|
|
|
static class Config { |
|
|
|
@ -139,15 +149,17 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public PersistenceExceptionTranslator peTranslator() { |
|
|
|
public PersistenceExceptionTranslator peTranslator() { |
|
|
|
PersistenceExceptionTranslator txlator = mock(PersistenceExceptionTranslator.class); |
|
|
|
return mock(PersistenceExceptionTranslator.class); |
|
|
|
return txlator; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface MyRepository { |
|
|
|
public interface MyRepository { |
|
|
|
|
|
|
|
|
|
|
|
int getInvocationCount(); |
|
|
|
int getInvocationCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Repository |
|
|
|
@Repository |
|
|
|
static class MyRepositoryImpl implements MyRepository { |
|
|
|
static class MyRepositoryImpl implements MyRepository { |
|
|
|
|
|
|
|
|
|
|
|
@ -165,11 +177,15 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface MyRepositoryWithScheduledMethod { |
|
|
|
public interface MyRepositoryWithScheduledMethod { |
|
|
|
|
|
|
|
|
|
|
|
int getInvocationCount(); |
|
|
|
int getInvocationCount(); |
|
|
|
public void scheduled(); |
|
|
|
|
|
|
|
|
|
|
|
void scheduled(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Repository |
|
|
|
@Repository |
|
|
|
static class MyRepositoryWithScheduledMethodImpl implements MyRepositoryWithScheduledMethod { |
|
|
|
static class MyRepositoryWithScheduledMethodImpl implements MyRepositoryWithScheduledMethod { |
|
|
|
|
|
|
|
|
|
|
|
|