This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from dominik42/master
repro project for SPR-8853
- Loading branch information
Showing
11 changed files
with
333 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.springframework.issues</groupId> | ||
<artifactId>SPR-8853</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<hibernate-version>3.6.0.Final</hibernate-version> | ||
<hibernate.jpa-version>1.0.0.Final</hibernate.jpa-version> | ||
<hibernate.validator-version>4.1.0.Final</hibernate.validator-version> | ||
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding> | ||
<org.aspectj-version>1.6.9</org.aspectj-version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>3.1.0.RC1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>1.2.16</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.8</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-orm</artifactId> | ||
<version>3.1.0.RC1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>${hibernate-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate.javax.persistence</groupId> | ||
<artifactId>hibernate-jpa-2.0-api</artifactId> | ||
<version>${hibernate.jpa-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>${hibernate.validator-version}</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-impl</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjrt</artifactId> | ||
<version>${org.aspectj-version}</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>cglib</groupId> | ||
<artifactId>cglib</artifactId> | ||
<version>2.2.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hsqldb</groupId> | ||
<artifactId>hsqldb</artifactId> | ||
<version>2.2.4</version> | ||
</dependency> | ||
</dependencies> | ||
<repositories> | ||
<!-- <repository> --> | ||
<!-- <snapshots> --> | ||
<!-- <enabled>false</enabled> --> | ||
<!-- </snapshots> --> | ||
<!-- <id>repo1.maven.org</id> --> | ||
<!-- <name>Maven Central Repository</name> --> | ||
<!-- <url>http://repo1.maven.org/maven2</url> --> | ||
<!-- </repository> --> | ||
<repository> | ||
<id>spring-maven-snapshot</id> | ||
<name>Springframework Maven Snapshot Repository</name> | ||
<url>http://maven.springframework.org/snapshot</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>spring-milestone</id> | ||
<name>Spring Portfolio Milestone Repository</name> | ||
<url>http://s3.amazonaws.com/maven.springframework.org/milestone</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<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> | ||
</project> | ||
|
52 changes: 52 additions & 0 deletions
52
SPR-8853/src/main/java/org/springframework/issues/AppConfigWithComponentScan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.springframework.issues; | ||
|
||
import java.util.Properties; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportResource; | ||
import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean; | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = "org.springframework.issues", excludeFilters = {@ComponentScan.Filter(Configuration.class)}) | ||
@ImportResource({"classpath*:properties-config.xml"}) | ||
public class AppConfigWithComponentScan | ||
{ | ||
@Bean | ||
public SessionFactory sessionFactory() throws Exception | ||
{ | ||
AnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean(); | ||
bean.setDataSource(dataSource()); | ||
bean.setPackagesToScan(new String[] {"org.springframework.issues"}); | ||
bean.setHibernateProperties(hibernateProps()); | ||
bean.afterPropertiesSet(); | ||
return bean.getObject(); | ||
} | ||
|
||
private Properties hibernateProps() | ||
{ | ||
Properties jpaProperties = new Properties(); | ||
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); | ||
jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop"); | ||
jpaProperties.put("hibernate.show_sql", false); | ||
jpaProperties.put("hibernate.format_sql", true); | ||
return jpaProperties; | ||
} | ||
|
||
@Value("${db.driverClass}") private String driverClass; | ||
@Value("${db.jdbcUrl}") private String jdbcUrl; | ||
@Value("${db.user}") private String user; | ||
@Value("${db.password}") private String password; | ||
|
||
@Bean | ||
public DataSource dataSource() | ||
{ | ||
return new DriverManagerDataSource(driverClass, jdbcUrl, user, password); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
SPR-8853/src/main/java/org/springframework/issues/AppConfigWithoutComponentScan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.springframework.issues; | ||
|
||
import java.util.Properties; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportResource; | ||
import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean; | ||
|
||
@Configuration | ||
//@ComponentScan(basePackages = "org.springframework.issues", excludeFilters = {@ComponentScan.Filter(Configuration.class)}) | ||
@ImportResource({"classpath*:properties-config.xml","classpath*:componentScan.xml"}) | ||
public class AppConfigWithoutComponentScan | ||
{ | ||
@Bean | ||
public SessionFactory sessionFactory() throws Exception | ||
{ | ||
AnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean(); | ||
bean.setDataSource(dataSource()); | ||
bean.setPackagesToScan(new String[] {"org.springframework.issues"}); | ||
bean.setHibernateProperties(hibernateProps()); | ||
bean.afterPropertiesSet(); | ||
return bean.getObject(); | ||
} | ||
|
||
private Properties hibernateProps() | ||
{ | ||
Properties jpaProperties = new Properties(); | ||
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); | ||
jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop"); | ||
jpaProperties.put("hibernate.show_sql", false); | ||
jpaProperties.put("hibernate.format_sql", true); | ||
return jpaProperties; | ||
} | ||
|
||
@Value("${db.driverClass}") private String driverClass; | ||
@Value("${db.jdbcUrl}") private String jdbcUrl; | ||
@Value("${db.user}") private String user; | ||
@Value("${db.password}") private String password; | ||
|
||
@Bean | ||
public DataSource dataSource() | ||
{ | ||
return new DriverManagerDataSource(driverClass, jdbcUrl, user, password); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.springframework.issues; | ||
|
||
public class Bar { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
SPR-8853/src/main/java/org/springframework/issues/CustomerDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.springframework.issues; | ||
|
||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class CustomerDAO extends HibernateDaoSupport | ||
{ | ||
public void method () | ||
{ | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
SPR-8853/src/main/java/org/springframework/issues/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.springframework.issues; | ||
|
||
public class Foo { | ||
|
||
private final Bar bar; | ||
|
||
public Foo(Bar bar) { | ||
this.bar = bar; | ||
} | ||
|
||
public Bar getBar() { | ||
return this.bar; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
SPR-8853/src/test/java/org/springframework/issues/ReproTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.springframework.issues; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Test; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
/** | ||
* Unit test that reproduces an issue reported against SPR JIRA. @Test methods within | ||
* need not pass with the green bar! Rather they should fail in such a way that | ||
* demonstrates the reported issue. | ||
*/ | ||
public class ReproTests | ||
{ | ||
|
||
@Test // this fails | ||
public void testAppConfigWithComponentScan() | ||
{ | ||
// use the java config class with @ComponentScan annotation | ||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfigWithComponentScan.class); | ||
CustomerDAO dao = ctx.getBean(CustomerDAO.class); | ||
assertNotNull(dao); | ||
} | ||
|
||
@Test // this works | ||
public void testAppConfigWithoutComponentScan() | ||
{ | ||
// use the java config with componentScan taken from external resource | ||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfigWithoutComponentScan.class); | ||
CustomerDAO dao = ctx.getBean(CustomerDAO.class); | ||
assertNotNull(dao); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?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:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" | ||
default-autowire="byType"> | ||
|
||
<context:component-scan base-package="org.springframework.issues" use-default-filters="false"> | ||
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/> | ||
</context:component-scan> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# fastest dev time settings: mem-based HSQL | ||
db.driverClass=org.hsqldb.jdbcDriver | ||
db.jdbcUrl=jdbc:hsqldb:mem:issueTest | ||
db.user=sa | ||
db.password= | ||
hibernate.dialect=org.hibernate.dialect.HSQLDialect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
log4j.rootCategory=ERROR, stdout | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n | ||
|
||
log4j.category.org.springframework=WARN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd" | ||
default-autowire="byType"> | ||
<context:property-placeholder location="classpath*:jdbc.properties"/> | ||
</beans> |