首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用XML配置的

问使用XML配置的
EN

Stack Overflow用户
提问于 2015-12-02 16:22:49
回答 1查看 304关注 0票数 0

我试图在基于XML的配置中使用Spring配置,但是使用特性的bean永远不会被创建。你能提出什么可能是根本原因吗。我的应用程序使用了Spring 3.2。

我的Java类-

代码语言:javascript
复制
@Configuration
@ComponentScan({ "com.aexp.mars" })
@Profile("dev")
@PropertySource("classpath:messages.properties" )
@ImportResource("classpath:/spring/spring-profiles.xml")
public class SpringConfigDev{

    private DriverManagerDataSource dataSource;

Spring配置-

代码语言:javascript
复制
<beans profile="dev">
    <bean id="marsURLConfig" class="com.aexp.mars.common.utils.MarsURLConfig">
        <property name="solrBaseURL" value="http://localhost:8080/solr"/>
    </bean> 
</beans>

开发配置文件是使用以下主要方法中的代码激活的

代码语言:javascript
复制
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        String env = "dev";

        context.getEnvironment().setActiveProfiles(env);

        context.register(SpringConfigDev.class);

        context.refresh();

我的Spring组件之一使用了MarsURLConfig类型的自动装配,下面是例外情况。

代码语言:javascript
复制
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“,应用程序将正确工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-02 19:22:00

这似乎是Spring3.2Java配置方法的已知限制。当我们使用Java时,Spring 3.2不支持创建bean级别的配置文件,而且由于我试图从基于Java的配置类加载XML,所以它对我没有起作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34047737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档