From 019978395c5dc9ae85e258de179566494f0fd536 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 26 Jul 2012 12:02:56 -0400 Subject: [PATCH] Add project for SPR-9638 --- .../webapp/WEB-INF/spring/servlet-context.xml | 4 +- SPR-9638/pom.xml | 62 +++++++++++++++++++ .../issues/ControllerAdvisor.java | 37 +++++++++++ .../issues/DefaultTestController.java | 26 ++++++++ .../issues/TestController.java | 20 ++++++ .../issues/TestInitializingBean.java | 41 ++++++++++++ SPR-9638/src/main/resources/.gitignore | 0 .../org/springframework/issues/config.xml | 20 ++++++ .../springframework/issues/ReproTests.java | 38 ++++++++++++ SPR-9638/src/test/resources/log4j.properties | 7 +++ 10 files changed, 253 insertions(+), 2 deletions(-) create mode 100644 SPR-9638/pom.xml create mode 100644 SPR-9638/src/main/java/org/springframework/issues/ControllerAdvisor.java create mode 100644 SPR-9638/src/main/java/org/springframework/issues/DefaultTestController.java create mode 100644 SPR-9638/src/main/java/org/springframework/issues/TestController.java create mode 100644 SPR-9638/src/main/java/org/springframework/issues/TestInitializingBean.java create mode 100644 SPR-9638/src/main/resources/.gitignore create mode 100644 SPR-9638/src/main/resources/org/springframework/issues/config.xml create mode 100644 SPR-9638/src/test/java/org/springframework/issues/ReproTests.java create mode 100644 SPR-9638/src/test/resources/log4j.properties diff --git a/SPR-9601/src/main/webapp/WEB-INF/spring/servlet-context.xml b/SPR-9601/src/main/webapp/WEB-INF/spring/servlet-context.xml index 65a62911..1002774b 100644 --- a/SPR-9601/src/main/webapp/WEB-INF/spring/servlet-context.xml +++ b/SPR-9601/src/main/webapp/WEB-INF/spring/servlet-context.xml @@ -21,8 +21,6 @@ - - @@ -32,4 +30,6 @@ + + diff --git a/SPR-9638/pom.xml b/SPR-9638/pom.xml new file mode 100644 index 00000000..edafd3f2 --- /dev/null +++ b/SPR-9638/pom.xml @@ -0,0 +1,62 @@ + + 4.0.0 + org.springframework.issues + SPR-9638 + 1.0-SNAPSHOT + jar + + + org.springframework + spring-context + 3.2.0.BUILD-SNAPSHOT + + + log4j + log4j + 1.2.16 + + + junit + junit + 4.8 + test + + + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.springsource.org/snapshot + true + + + + UTF8 + + + + + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + maven-surefire-plugin + 2.7.2 + + + **/*Tests.java + + + **/*Abstract*.java + + + + + + + diff --git a/SPR-9638/src/main/java/org/springframework/issues/ControllerAdvisor.java b/SPR-9638/src/main/java/org/springframework/issues/ControllerAdvisor.java new file mode 100644 index 00000000..adfcda70 --- /dev/null +++ b/SPR-9638/src/main/java/org/springframework/issues/ControllerAdvisor.java @@ -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()); + } + +} diff --git a/SPR-9638/src/main/java/org/springframework/issues/DefaultTestController.java b/SPR-9638/src/main/java/org/springframework/issues/DefaultTestController.java new file mode 100644 index 00000000..c69747fc --- /dev/null +++ b/SPR-9638/src/main/java/org/springframework/issues/DefaultTestController.java @@ -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() { + } + +} diff --git a/SPR-9638/src/main/java/org/springframework/issues/TestController.java b/SPR-9638/src/main/java/org/springframework/issues/TestController.java new file mode 100644 index 00000000..47453ebf --- /dev/null +++ b/SPR-9638/src/main/java/org/springframework/issues/TestController.java @@ -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 { + +} \ No newline at end of file diff --git a/SPR-9638/src/main/java/org/springframework/issues/TestInitializingBean.java b/SPR-9638/src/main/java/org/springframework/issues/TestInitializingBean.java new file mode 100644 index 00000000..a80c07ab --- /dev/null +++ b/SPR-9638/src/main/java/org/springframework/issues/TestInitializingBean.java @@ -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"); + } + +} diff --git a/SPR-9638/src/main/resources/.gitignore b/SPR-9638/src/main/resources/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/SPR-9638/src/main/resources/org/springframework/issues/config.xml b/SPR-9638/src/main/resources/org/springframework/issues/config.xml new file mode 100644 index 00000000..e1638473 --- /dev/null +++ b/SPR-9638/src/main/resources/org/springframework/issues/config.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + diff --git a/SPR-9638/src/test/java/org/springframework/issues/ReproTests.java b/SPR-9638/src/test/java/org/springframework/issues/ReproTests.java new file mode 100644 index 00000000..13178b0f --- /dev/null +++ b/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())); + } + +} diff --git a/SPR-9638/src/test/resources/log4j.properties b/SPR-9638/src/test/resources/log4j.properties new file mode 100644 index 00000000..82776b7b --- /dev/null +++ b/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 \ No newline at end of file