Mobilefirst 8.0.0 Spring bean 配置失败
Mobilefirst 8.0.0 Spring bean configuration fails
这可能有点远...
我正在尝试注册 bean 和 jax-rs 资源,但没有成功。
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
我有一个配置 class,它应该连接 bean。
@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
很空白
<?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 吗?
好吧,我终于做到了...需要在调用 bean 的服务上专门扫描我的配置包(据我所知)。
@ComponentScan(basePackages = {"com.example.adapter.configuration"})
public class FeatureToggleServiceImpl implements FeatureToggleService {}
如果有人知道放置 @ComponentScan
的更好位置,我很想知道。
这可能有点远...
我正在尝试注册 bean 和 jax-rs 资源,但没有成功。
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
我有一个配置 class,它应该连接 bean。
@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
很空白
<?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 吗?
好吧,我终于做到了...需要在调用 bean 的服务上专门扫描我的配置包(据我所知)。
@ComponentScan(basePackages = {"com.example.adapter.configuration"})
public class FeatureToggleServiceImpl implements FeatureToggleService {}
如果有人知道放置 @ComponentScan
的更好位置,我很想知道。