Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 216f632

Browse files
committed
Merge pull request #81 from mikeycmccarthy/master
* pull81: Add repro project for SPR-11915
2 parents b3d5b07 + f3fa163 commit 216f632

File tree

7 files changed

+227
-0
lines changed

7 files changed

+227
-0
lines changed

SPR-11915/pom.xml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-11915</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<properties>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
12+
<java.version>1.6</java.version>
13+
<spring.version>4.0.4.RELEASE</spring.version>
14+
<slf4j.version>1.7.5</slf4j.version>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-context</artifactId>
21+
<version>${spring.version}</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-jdbc</artifactId>
27+
<version>${spring.version}</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-test</artifactId>
33+
<version>${spring.version}</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>com.h2database</groupId>
38+
<artifactId>h2</artifactId>
39+
<version>1.3.173</version>
40+
<scope>test</scope>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.slf4j</groupId>
45+
<artifactId>slf4j-api</artifactId>
46+
<version>${slf4j.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.slf4j</groupId>
50+
<artifactId>slf4j-log4j12</artifactId>
51+
<version>${slf4j.version}</version>
52+
<scope>runtime</scope>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>junit</groupId>
57+
<artifactId>junit</artifactId>
58+
<version>4.11</version>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-compiler-plugin</artifactId>
68+
<version>2.5.1</version>
69+
<configuration>
70+
<source>${java.version}</source>
71+
<target>${java.version}</target>
72+
</configuration>
73+
</plugin>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-surefire-plugin</artifactId>
77+
<version>2.12.4</version>
78+
<configuration>
79+
<includes>
80+
<include>**/*Tests.java</include>
81+
<include>**/*Test.java</include>
82+
</includes>
83+
<excludes>
84+
<exclude>**/*Abstract*.java</exclude>
85+
</excludes>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
91+
<repositories>
92+
<repository>
93+
<id>spring-maven-snapshot</id>
94+
<name>Springframework Maven Snapshot Repository</name>
95+
<url>http://repo.spring.io/snapshot</url>
96+
<snapshots>
97+
<enabled>true</enabled>
98+
</snapshots>
99+
</repository>
100+
</repositories>
101+
102+
</project>
103+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.springframework.issues;
2+
3+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
4+
import org.springframework.context.ApplicationContextInitializer;
5+
import org.springframework.context.ConfigurableApplicationContext;
6+
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
7+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
8+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
9+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
10+
import org.springframework.transaction.PlatformTransactionManager;
11+
12+
import javax.sql.DataSource;
13+
14+
public class AppInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
15+
16+
@Override
17+
public void initialize(ConfigurableApplicationContext applicationContext) {
18+
19+
ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
20+
21+
DataSource dataSource = createDataSource();
22+
23+
beanFactory.registerSingleton("dataSource", dataSource);
24+
25+
beanFactory.registerSingleton("myTransactionManager", createPlatformTransactionManager(dataSource));
26+
27+
}
28+
29+
public DataSource createDataSource() {
30+
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
31+
return dataSource;
32+
}
33+
34+
public PlatformTransactionManager createPlatformTransactionManager(DataSource dataSource) {
35+
return new DataSourceTransactionManager(dataSource);
36+
}
37+
38+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.issues;
2+
3+
public interface ServiceWithTransactionality {
4+
5+
public void doSomething();
6+
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.springframework.issues;
2+
3+
import org.springframework.jdbc.core.JdbcTemplate;
4+
import org.springframework.transaction.annotation.Transactional;
5+
6+
import javax.sql.DataSource;
7+
8+
@Transactional("myTransactionManager")
9+
public class ServiceWithTransactionalityImpl implements ServiceWithTransactionality {
10+
11+
private final JdbcTemplate jdbcTemplate;
12+
13+
public ServiceWithTransactionalityImpl(DataSource dataSource) {
14+
jdbcTemplate = new JdbcTemplate(dataSource);
15+
}
16+
17+
@Override
18+
public void doSomething() {
19+
this.jdbcTemplate.getMaxRows();
20+
}
21+
}

SPR-11915/src/main/resources/.gitignore

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.springframework.issues;
2+
3+
import static org.hamcrest.CoreMatchers.sameInstance;
4+
import static org.junit.Assert.assertThat;
5+
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.context.support.GenericXmlApplicationContext;
12+
import org.springframework.test.context.ContextConfiguration;
13+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14+
import org.springframework.transaction.annotation.EnableTransactionManagement;
15+
16+
import javax.sql.DataSource;
17+
18+
/**
19+
* Unit test that reproduces an issue reported against SPR JIRA. @Test methods within
20+
* need not pass with the green bar! Rather they should fail in such a way that
21+
* demonstrates the reported issue.
22+
*/
23+
@RunWith(SpringJUnit4ClassRunner.class)
24+
@ContextConfiguration(classes = ReproTests.TestConfig.class,
25+
initializers = AppInitializer.class)
26+
public class ReproTests {
27+
28+
@Autowired
29+
private ServiceWithTransactionality testObject;
30+
31+
@Test
32+
public void test_something() throws Exception {
33+
testObject.doSomething();
34+
}
35+
36+
@Configuration
37+
@EnableTransactionManagement
38+
static class TestConfig {
39+
40+
@Autowired
41+
public DataSource dataSource;
42+
43+
@Bean
44+
public ServiceWithTransactionality serviceWithTransactionality() {
45+
return new ServiceWithTransactionalityImpl(dataSource);
46+
}
47+
48+
49+
}
50+
51+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootCategory=ERROR, stdout
2+
3+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
6+
7+
log4j.category.org.springframework=WARN

0 commit comments

Comments
 (0)