Permalink
Browse files

Add repro project for SPR-9464

  • Loading branch information...
cbeams committed Jun 5, 2012
1 parent 4b7474b commit a1584d7aa1906ab06ffe0dc8161c187647c8f6cc
View
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.issues</groupId>
<artifactId>SPR-9464</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SPR-9464</name>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<testSourceDirectory>src</testSourceDirectory>
<testResources>
<testResource>
<directory>src</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*Abstract*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring.milestone</id>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.0.M1</spring.version>
<slf4j.version>1.6.4</slf4j.version>
</properties>
</project>
@@ -0,0 +1,39 @@
package org.springframework.issues.config;
import javax.annotation.PreDestroy;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
@Configuration
public class RepositoryConfig {
private static final Logger logger = LoggerFactory.getLogger(RepositoryConfig.class);
private EmbeddedDatabase db;
@Bean(name = "dataSource")
DataSource dataSource() {
logger.info("Setting up database");
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).
addScript("schema.sql").
addScript("test-data.sql").build();
this.db = db;
return db;
}
@PreDestroy
void destroy() {
logger.info("Shutting down database");
this.db.shutdown();
}
}
@@ -0,0 +1,14 @@
package org.springframework.issues.config.java_centric;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.issues.config.RepositoryConfig;
@Configuration
@ImportResource("classpath:org/springframework/issues/config/java_centric/app-config.xml")
@Import(RepositoryConfig.class)
@ComponentScan(basePackages="org.springframework.issues.service")
public class AppConfig {
}
@@ -0,0 +1,30 @@
<?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:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:failFast="true"
p:configLocation="classpath:org/springframework/issues/config/mybatis-config.xml" />
<bean class="org.mybatis.spring.SqlSessionTemplate"
c:sqlSessionFactory-ref="sqlSessionFactory" />
<!-- ideally only the following declaration would be necessary, however because
MapperScannerConfigurer is a BeanDefinitionRegistryPostProcessor and because
this file is included via @ImportResource, it is "too late" for this component
to be properly treated as a BDRPP.
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="org.springframework.issues.dao" />
-->
<!-- The workaround is to include an explicit MapperFactoryBean -->
<bean id="testMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"
p:mapperInterface="org.springframework.issues.dao.TestDao"
p:sqlSessionFactory-ref="sqlSessionFactory" />
</beans>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>
@@ -0,0 +1,12 @@
package org.springframework.issues.config.xml_centric;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.issues.config.RepositoryConfig;
@Configuration
@Import(RepositoryConfig.class)
@ComponentScan(basePackages="org.springframework.issues.service")
public class AppConfig {
}
@@ -0,0 +1,37 @@
<?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:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- enable annotation-config in order to process @Configuration beans -->
<context:annotation-config/>
<!-- include the AppConfig @Configuration class -->
<bean class="org.springframework.issues.config.xml_centric.AppConfig"/>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:failFast="true"
p:configLocation="classpath:org/springframework/issues/config/mybatis-config.xml" />
<bean class="org.mybatis.spring.SqlSessionTemplate"
c:sqlSessionFactory-ref="sqlSessionFactory" />
<!-- in the XML-centric case, MapperScannerConfigurer works as expected, because
this BeanDefinitionRegistryPostProcessor is added early enough to be processed
at the right time.
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="org.springframework.issues.dao" />
<!-- Therefore there is no need for this workaround
<bean id="testMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"
p:mapperInterface="org.springframework.issues.dao.TestDao"
p:sqlSessionFactory-ref="sqlSessionFactory" />
-->
</beans>
@@ -0,0 +1,6 @@
package org.springframework.issues.dao;
public interface TestDao {
int queryDummyValue();
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springframework.issues.dao.TestDao">
<select id="queryDummyValue" resultType="_int">
<![CDATA[
SELECT dummy_value
FROM test
WHERE dummy_key = 'test_key'
]]>
</select>
</mapper>
@@ -0,0 +1,6 @@
package org.springframework.issues.service;
public interface TestService {
int queryDummyValue();
}
@@ -0,0 +1,18 @@
package org.springframework.issues.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.issues.dao.TestDao;
import org.springframework.stereotype.Service;
@Service
public class TestServiceImpl implements TestService {
@Autowired
private TestDao testDao;
@Override
public int queryDummyValue() {
return testDao.queryDummyValue();
}
}
@@ -0,0 +1,37 @@
package org.springframework.issues.spr9464;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.issues.service.TestService;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
public class ReproTests {
@Test
public void javaCentric() {
GenericApplicationContext appContext = new AnnotationConfigApplicationContext(
org.springframework.issues.config.java_centric.AppConfig.class);
TestService service = appContext.getBean(TestService.class);
assertThat(service.queryDummyValue(), equalTo(12345));
appContext.close();
}
@Test
public void xmlCentric() {
GenericApplicationContext appContext = new GenericXmlApplicationContext(
"classpath:org/springframework/issues/config/xml_centric/app-config.xml");
TestService service = appContext.getBean(TestService.class);
assertThat(service.queryDummyValue(), equalTo(12345));
appContext.close();
}
}
View
@@ -0,0 +1,2 @@
DROP TABLE test IF EXISTS;
CREATE TABLE test (dummy_key VARCHAR(255), dummy_value INTEGER);
@@ -0,0 +1 @@
INSERT INTO test (dummy_key, dummy_value) VALUES ('test_key', 12345);

0 comments on commit a1584d7

Please sign in to comment.