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

Commit

Permalink
Add project for SPR-9638
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jul 26, 2012
1 parent 5b062d5 commit 0199783
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 2 deletions.
4 changes: 2 additions & 2 deletions SPR-9601/src/main/webapp/WEB-INF/spring/servlet-context.xml
Expand Up @@ -21,8 +21,6 @@
</property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>

<mvc:annotation-driven />

<mvc:view-controller path="/" view-name="home" />
Expand All @@ -32,4 +30,6 @@
<property name="suffix" value=".jsp" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>

</beans>
62 changes: 62 additions & 0 deletions SPR-9638/pom.xml
@@ -0,0 +1,62 @@
<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-9638</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</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>
</dependencies>
<repositories>
<repository>
<id>spring-maven-snapshot</id>
<name>Springframework Maven Snapshot Repository</name>
<url>http://repo.springsource.org/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
</properties>
<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>

@@ -0,0 +1,37 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.issues;

import java.lang.reflect.Method;

import org.springframework.aop.interceptor.SimpleTraceInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Controller;

@SuppressWarnings("serial")
public class ControllerAdvisor extends DefaultPointcutAdvisor {

public ControllerAdvisor() {
super(new StaticMethodMatcherPointcut() {
public boolean matches(Method method, Class<?> targetClass) {
return (AnnotationUtils.findAnnotation(targetClass, Controller.class) != null);
}
}, new SimpleTraceInterceptor());
}

}
@@ -0,0 +1,26 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.issues;

import org.springframework.stereotype.Controller;

@Controller
public class DefaultTestController implements TestController {

public void handle() {
}

}
@@ -0,0 +1,20 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.issues;

public interface TestController {

}
@@ -0,0 +1,41 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.issues;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class TestInitializingBean implements InitializingBean, ApplicationContextAware {

private ApplicationContext applicationContext;

private Class<?> controllerType;

public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

public Class<?> getControllerType() {
return this.controllerType;
}

public void afterPropertiesSet() throws Exception {
this.controllerType = this.applicationContext.getType("testController");
}

}
Empty file.
20 changes: 20 additions & 0 deletions SPR-9638/src/main/resources/org/springframework/issues/config.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />

<bean class="org.springframework.issues.ControllerAdvisor" />

<beans profile="success">
<bean id="testController" class="org.springframework.issues.DefaultTestController" />
<bean class="org.springframework.issues.TestInitializingBean" />
</beans>

<beans profile="failure">
<bean class="org.springframework.issues.TestInitializingBean" />
<bean id="testController" class="org.springframework.issues.DefaultTestController" />
</beans>

</beans>
38 changes: 38 additions & 0 deletions SPR-9638/src/test/java/org/springframework/issues/ReproTests.java
@@ -0,0 +1,38 @@
package org.springframework.issues;

import static org.junit.Assert.assertTrue;

import java.lang.reflect.Proxy;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ReproTests {

@Test
public void success() {

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setConfigLocation("classpath:org/springframework/issues/config.xml");
context.getEnvironment().setActiveProfiles("success");
context.refresh();

TestInitializingBean bean = context.getBean(TestInitializingBean.class);

assertTrue(Proxy.isProxyClass(bean.getControllerType()));
}

@Test
public void failure() {

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setConfigLocation("classpath:org/springframework/issues/config.xml");
context.getEnvironment().setActiveProfiles("failure");
context.refresh();

TestInitializingBean bean = context.getBean(TestInitializingBean.class);

assertTrue(Proxy.isProxyClass(bean.getControllerType()));
}

}
7 changes: 7 additions & 0 deletions SPR-9638/src/test/resources/log4j.properties
@@ -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

0 comments on commit 0199783

Please sign in to comment.