236 Star 831 Fork 312

阿库玛 / hasor

4.1.4 DatawayService 接口在 Spring 中配置报错

Done
wanghai  Opened this issue
@Bean
public DatawayService datawayService(AppContext appContext) {
    return appContext.getInstance(DatawayService.class);
}

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-05 13:02:45.864 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'datawayService': Unsatisfied dependency expressed through field 'dataQL'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.hasor.dataql.DataQL' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject(), @javax.inject.Named(value="net.hasor.dataway.config.DatawayModule")}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.luban.unionuser.ExampleApplication.main(ExampleApplication.java:13)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.hasor.dataql.DataQL' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject(), @javax.inject.Named(value="net.hasor.dataway.config.DatawayModule")}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1253)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
... 19 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:55361', transport: 'socket'

输入图片说明

10885 zycgit 1578914733 total 2 participants

Comments (2)

10885 zycgit 1578914733
阿库玛 2020-05-07 23:05 owner

该问题原因为 DatawayServiceImpl 实现类内部使用了 JSR-330 的依赖注入。这个注入已经被 Hasor 内部处理好了。但是 Spring 在处理这个 Bean 的时候又对 JSR-330 标记的类做了二次处理。 因此产生了冲突。

解决办法2个:

  1. 用工厂方式来获取 DatawayService。
  2. 升级到 4.1.5 版本。 4.1.5 中将依赖注入方式从 JSR330 改为了 Hasor 自己的注解。

public class DatawayServiceImpl implements DatawayService {
@inject
@Named(ISOLATION_CONTEXT)
private DataQL dataQL;
@inject
private ApiCallService callService;

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority
Java
1
https://gitee.com/zycgit/hasor.git
git@gitee.com:zycgit/hasor.git
zycgit
hasor
hasor

Search