首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mobilefirst 8.0.0 Spring bean配置失败

Mobilefirst 8.0.0 Spring bean配置失败
EN

Stack Overflow用户
提问于 2018-08-29 09:30:32
回答 1查看 393关注 0票数 0

这可能有点小机会...

我正在尝试注册bean和jax-rs资源,但是没有任何成功。

代码语言:javascript
复制
java.lang.RuntimeException: User code thrown exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.mfpdev.adapters.spring.integration.JAXRSResourcesRegistryImpl#0' defined in class path resource [applicationContext.xml]: Cannot create inner bean 'com.example.FeatureToggleAdapterResource#311640f7' of type [com.example.FeatureToggleAdapterResource] while setting bean property 'resources' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.FeatureToggleAdapterResource#311640f7' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'featureToggleService' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'featureToggleService' available

我有一个config类,它应该连接bean。

代码语言:javascript
复制
@Configuration
@ComponentScan
public class BeanConfig {

    @Bean(name = "configurationService")
    public ConfigurationService configurationService() {
        return new ConfigurationServiceImpl();
    }

    @Bean(name = "featureToggleService")
    public FeatureToggleService featureToggleService() {
        return new FeatureToggleServiceImpl(jdbcTemplate());
    }
}

我的applicationContext.xml是空白的

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- Define the list of JAX-RS resources to use: -->
    <bean class="com.github.mfpdev.adapters.spring.integration.JAXRSResourcesRegistryImpl">
        <property name="resources">
            <list>
                <bean class="com.example.FeatureToggleAdapterResource">
                    <constructor-arg ref="featureToggleService"/>
                </bean>
            </list>
        </property>
    </bean>

</beans>

我正在利用https://github.com/mfpdev/mfp-advanced-adapters-samples

我唯一的选择是通过XML连接bean吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-29 09:49:12

好的,我终于到了那里……需要专门扫描对bean进行调用的服务上的配置包(据我所知)。

代码语言:javascript
复制
@ComponentScan(basePackages = {"com.example.adapter.configuration"})
public class FeatureToggleServiceImpl implements FeatureToggleService {}

如果有人知道放@ComponentScan的更好的地方,我很想知道。

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

https://stackoverflow.com/questions/52068289

复制
相关文章

相似问题

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