Skip to content

Commit d356205

Browse files
committed
Introduce @EnableSpringConfigured
Equivalent to <context:spring-configured/>. Also update @EnableLoadTimeWeaving Javadoc and spring-configured XSD documentation to reflect. Issue: SPR-7888
1 parent 4318ccd commit d356205

File tree

6 files changed

+146
-2
lines changed

6 files changed

+146
-2
lines changed

org.springframework.aspects/ivy.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
</publications>
2828

2929
<dependencies>
30+
<dependency org="net.sourceforge.cglib" name="com.springsource.net.sf.cglib" rev="2.2.0" conf="test->runtime"/>
3031
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile, commons-logging->compile"/>
3132
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="${aspectj.version}" conf="optional, aspectj->compile"/>
3233
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="test->compile"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2002-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.beans.factory.aspectj;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.context.annotation.Import;
26+
27+
/**
28+
* Signals the current application context to apply dependency injection to non-managed
29+
* classes that are instantiated outside of the Spring bean factory (typically classes
30+
* annotated with the @{@link org.springframework.beans.factory.annotation.Configurable
31+
* Configurable} annotation).
32+
*
33+
* <p>Similar to functionality found in Spring's {@code <context:spring-configured>} XML
34+
* element. Often used in conjunction with {@link
35+
* org.springframework.context.annotation.EnableLoadTimeWeaving @EnableLoadTimeWeaving}.
36+
*
37+
* @author Chris Beams
38+
* @since 3.1
39+
* @see org.springframework.context.annotation.EnableLoadTimeWeaving
40+
*/
41+
@Target(ElementType.TYPE)
42+
@Retention(RetentionPolicy.RUNTIME)
43+
@Documented
44+
@Import(SpringConfiguredConfiguration.class)
45+
public @interface EnableSpringConfigured {
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2002-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.beans.factory.aspectj;
18+
19+
import org.springframework.beans.factory.config.BeanDefinition;
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.context.annotation.Role;
23+
24+
/**
25+
* {@code @Configuration} class that registers an {@link AnnotationBeanConfigurerAspect}
26+
* capable of performing dependency injection services for non-Spring managed objects
27+
* annotated with @{@link org.springframework.beans.factory.annotation.Configurable
28+
* Configurable}.
29+
*
30+
* <p>This configuration class is automatically imported when using the @{@link
31+
* EnableSpringConfigured} annotation. See {@code @EnableSpringConfigured} Javadoc for
32+
* complete usage details.
33+
*
34+
* @author Chris Beams
35+
* @since 3.1
36+
* @see EnableSpringConfigured
37+
*/
38+
@Configuration
39+
public class SpringConfiguredConfiguration {
40+
41+
public static final String BEAN_CONFIGURER_ASPECT_BEAN_NAME =
42+
"org.springframework.context.config.internalBeanConfigurerAspect";
43+
44+
@Bean(name=BEAN_CONFIGURER_ASPECT_BEAN_NAME)
45+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
46+
public AnnotationBeanConfigurerAspect beanConfigurerAspect() {
47+
return AnnotationBeanConfigurerAspect.aspectOf();
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2002-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.beans.factory.aspectj;
18+
19+
import org.springframework.context.ConfigurableApplicationContext;
20+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
21+
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.context.annotation.ImportResource;
23+
24+
/**
25+
* Tests that @EnableSpringConfigured properly registers an
26+
* {@link AnnotationBeanConfigurerAspect}, just as does {@code <context:spring-configured>}
27+
*
28+
* @author Chris Beams
29+
* @since 3.1
30+
*/
31+
public class AnnotationBeanConfigurerTests extends AbstractBeanConfigurerTests {
32+
33+
@Override
34+
protected ConfigurableApplicationContext createContext() {
35+
return new AnnotationConfigApplicationContext(Config.class);
36+
}
37+
38+
@Configuration
39+
@ImportResource("org/springframework/beans/factory/aspectj/beanConfigurerTests-beans.xml")
40+
@EnableSpringConfigured
41+
static class Config {
42+
}
43+
}

org.springframework.context/src/main/java/org/springframework/context/annotation/EnableLoadTimeWeaving.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
* <p>The two examples are equivalent with one significant exception: in the XML case,
118118
* the functionality of {@code <context:spring-configured>} is implicitly enabled when
119119
* {@code aspectj-weaving} is "on". This does not occur when using
120-
* {@code @EnableLoadTimeWeaving(aspectjWeaving=ENABLED)}, although this may change in
121-
* future revisions.
120+
* {@code @EnableLoadTimeWeaving(aspectjWeaving=ENABLED)}. Instead you must explicitly add
121+
* {@code @EnableSpringConfigured} (included in the {@code spring-aspects} module)
122122
*
123123
* @author Chris Beams
124124
* @since 3.1

org.springframework.context/src/main/resources/org/springframework/context/config/spring-context-3.1.xsd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@
360360
Signals the current application context to apply dependency injection
361361
to non-managed classes that are instantiated outside of the Spring bean
362362
factory (typically classes annotated with the @Configurable annotation).
363+
364+
See Javadoc for org.springframework.context.annotation.EnableSpringConfigured in the
365+
spring-aspects module for information on code-based alternatives to bootstrapping
366+
this functionality.
363367
]]></xsd:documentation>
364368
</xsd:annotation>
365369
<xsd:simpleType>

0 commit comments

Comments
 (0)