No found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:

后端 未结 13 808
时光说笑
时光说笑 2020-12-08 01:43

I am trying to write a SOAP service using Spring, however I receive a Dependency Injection issue. I\'m having problems using @Autowired through the Service like

相关标签:
13条回答
  • 2020-12-08 02:12

    I added @Service before impl class and the error is gone.

    @Service
    public class FCSPAnalysisImpl implements FCSPAnalysis
    {}
    
    0 讨论(0)
  • 2020-12-08 02:13

    We face this issue but had different reason, here is the reason:

    In our project found multiple bean entry with same bean name. 1 in applicationcontext.xml & 1 in dispatcherServlet.xml

    Example:

    <bean name="dataService" class="com.app.DataServiceImpl">
    <bean name="dataService" class="com.app.DataServiceController">
    

    & we are trying to autowired by dataService name.

    Solution: we changed the bean name & its solved.

    0 讨论(0)
  • 2020-12-08 02:13

    In my case I had to move the @Service annotation from the interface to the implementation class.

    0 讨论(0)
  • 2020-12-08 02:15

    When you use @DataJpaTest you need to load classes using @Import explicitly. It wouldn't load you for auto.

    0 讨论(0)
  • 2020-12-08 02:20

    Add the annotation @Repository to the implementation of UserDaoImpl

    @Repository
    public class UserDaoImpl implements UserDao {
        private static Log log = LogFactory.getLog(UserDaoImpl.class);
    
        @Autowired
        @Qualifier("sessionFactory")
        private LocalSessionFactoryBean sessionFactory;
    
        //...
    
    }
    
    0 讨论(0)
  • 2020-12-08 02:24

    I just solved this error happening in my tests.

    Just make sure your test class has all dependencies in the attributes of the class being tested annotated with @MockBean so SpringBoot test context can wire your classes correctly.

    Only if you are testing controller: you need also class annotations to load the Controller context propertly.

    Check it out:

    @DisplayName("UserController Adapter Test")
    @WebMvcTest(UserController.class)
    @AutoConfigureMockMvc(addFilters = false)
    @Import(TestConfig.class)
    public class UserControllerTest {
    
    @Autowired
    private MockMvc mockMvc;
    
    @Autowired
    private ObjectMapper objectMapper;
    
    @MockBean
    private CreateUserCommand createUserCommand;
    
    @MockBean
    private GetUserListQuery getUserListQuery;
    
    @MockBean
    private GetUserQuery getUserQuery;
    
    0 讨论(0)
提交回复
热议问题