我试图在基于XML的配置中使用Spring配置,但是使用特性的bean永远不会被创建。你能提出什么可能是根本原因吗。我的应用程序使用了Spring 3.2。
我的Java类-
@Configuration
@ComponentScan({ "com.aexp.mars" })
@Profile("dev")
@PropertySource("classpath:messages.properties" )
@ImportResource("classpath:/spring/spring-profiles.xml")
public class SpringConfigDev{
private DriverManagerDataSource dataSource;Spring配置-
<beans profile="dev">
<bean id="marsURLConfig" class="com.aexp.mars.common.utils.MarsURLConfig">
<property name="solrBaseURL" value="http://localhost:8080/solr"/>
</bean>
</beans>开发配置文件是使用以下主要方法中的代码激活的
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
String env = "dev";
context.getEnvironment().setActiveProfiles(env);
context.register(SpringConfigDev.class);
context.refresh();我的Spring组件之一使用了MarsURLConfig类型的自动装配,下面是例外情况。
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [com.aexp.mars.common.utils.MarsURLConfig] found
for dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}如果从xml中删除profile="dev“,应用程序将正确工作。
发布于 2015-12-02 19:22:00
这似乎是Spring3.2Java配置方法的已知限制。当我们使用Java时,Spring 3.2不支持创建bean级别的配置文件,而且由于我试图从基于Java的配置类加载XML,所以它对我没有起作用。
https://stackoverflow.com/questions/34047737
复制相似问题