Introduce @EnableSpringConfigured
Equivalent to <context:spring-configured/>. Also update @EnableLoadTimeWeaving Javadoc and spring-configured XSD documentation to reflect. Issue: SPR-7888
This commit is contained in:
parent
4318ccd9d5
commit
d35620511e
|
|
@ -27,6 +27,7 @@
|
|||
</publications>
|
||||
|
||||
<dependencies>
|
||||
<dependency org="net.sourceforge.cglib" name="com.springsource.net.sf.cglib" rev="2.2.0" conf="test->runtime"/>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile, commons-logging->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="${aspectj.version}" conf="optional, aspectj->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="test->compile"/>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2002-2011 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.beans.factory.aspectj;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* Signals the current application context to apply dependency injection to non-managed
|
||||
* classes that are instantiated outside of the Spring bean factory (typically classes
|
||||
* annotated with the @{@link org.springframework.beans.factory.annotation.Configurable
|
||||
* Configurable} annotation).
|
||||
*
|
||||
* <p>Similar to functionality found in Spring's {@code <context:spring-configured>} XML
|
||||
* element. Often used in conjunction with {@link
|
||||
* org.springframework.context.annotation.EnableLoadTimeWeaving @EnableLoadTimeWeaving}.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
* @see org.springframework.context.annotation.EnableLoadTimeWeaving
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import(SpringConfiguredConfiguration.class)
|
||||
public @interface EnableSpringConfigured {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2002-2011 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.beans.factory.aspectj;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Role;
|
||||
|
||||
/**
|
||||
* {@code @Configuration} class that registers an {@link AnnotationBeanConfigurerAspect}
|
||||
* capable of performing dependency injection services for non-Spring managed objects
|
||||
* annotated with @{@link org.springframework.beans.factory.annotation.Configurable
|
||||
* Configurable}.
|
||||
*
|
||||
* <p>This configuration class is automatically imported when using the @{@link
|
||||
* EnableSpringConfigured} annotation. See {@code @EnableSpringConfigured} Javadoc for
|
||||
* complete usage details.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
* @see EnableSpringConfigured
|
||||
*/
|
||||
@Configuration
|
||||
public class SpringConfiguredConfiguration {
|
||||
|
||||
public static final String BEAN_CONFIGURER_ASPECT_BEAN_NAME =
|
||||
"org.springframework.context.config.internalBeanConfigurerAspect";
|
||||
|
||||
@Bean(name=BEAN_CONFIGURER_ASPECT_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public AnnotationBeanConfigurerAspect beanConfigurerAspect() {
|
||||
return AnnotationBeanConfigurerAspect.aspectOf();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2002-2011 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.beans.factory.aspectj;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
/**
|
||||
* Tests that @EnableSpringConfigured properly registers an
|
||||
* {@link AnnotationBeanConfigurerAspect}, just as does {@code <context:spring-configured>}
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public class AnnotationBeanConfigurerTests extends AbstractBeanConfigurerTests {
|
||||
|
||||
@Override
|
||||
protected ConfigurableApplicationContext createContext() {
|
||||
return new AnnotationConfigApplicationContext(Config.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ImportResource("org/springframework/beans/factory/aspectj/beanConfigurerTests-beans.xml")
|
||||
@EnableSpringConfigured
|
||||
static class Config {
|
||||
}
|
||||
}
|
||||
|
|
@ -117,8 +117,8 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
|
|||
* <p>The two examples are equivalent with one significant exception: in the XML case,
|
||||
* the functionality of {@code <context:spring-configured>} is implicitly enabled when
|
||||
* {@code aspectj-weaving} is "on". This does not occur when using
|
||||
* {@code @EnableLoadTimeWeaving(aspectjWeaving=ENABLED)}, although this may change in
|
||||
* future revisions.
|
||||
* {@code @EnableLoadTimeWeaving(aspectjWeaving=ENABLED)}. Instead you must explicitly add
|
||||
* {@code @EnableSpringConfigured} (included in the {@code spring-aspects} module)
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
|
|
|
|||
|
|
@ -360,6 +360,10 @@
|
|||
Signals the current application context to apply dependency injection
|
||||
to non-managed classes that are instantiated outside of the Spring bean
|
||||
factory (typically classes annotated with the @Configurable annotation).
|
||||
|
||||
See Javadoc for org.springframework.context.annotation.EnableSpringConfigured in the
|
||||
spring-aspects module for information on code-based alternatives to bootstrapping
|
||||
this functionality.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
|
|
|
|||
Loading…
Reference in New Issue