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
You seems to be missing implementation for interface UserDao. If you look at the exception closely it says
No qualifying bean of type [edu.java.spring.ws.dao.UserDao] found for dependency:
The way @Autowired
works is that it would automatically look for implementation of a dependency you inject via an interface. In this case since there is no valid implementation of interface UserDao you get the error.Ensure you have a valid implementation for this class and your error should go.
Hope that helps.
I missed to add
@Controller("userBo") into UserBoImpl class.
The solution for this is adding this controller into Impl class.
Add repository annotation before your DAO Implementation Class. example:
@Repository
public class EmpDAOImpl extends BaseNamedParameterJdbcDaoSupportUAM
implements EmpDAO{
}
Could me multiple reason for this. But you want might forget to add as @Bean for component which you have did @Autowired.
In my case, i have forgot to decorate with @Bean which causing this issue.
Look at the exception:
No qualifying bean of type [edu.java.spring.ws.dao.UserDao] found for dependency
This means that there's no bean available to fulfill that dependency. Yes, you have an implementation of the interface, but you haven't created a bean for that implementation. You have two options:
UserDaoImpl
with @Component
or @Repository
, and let the component scan do the work for you, exactly as you have done with UserService
.UserBoImpl
.Remember that if you create the bean explicitly you need to put the definition before the component scan. In this case the order is important.
In my case, the application context is not loaded because I add @DataJpaTest
annotation. When I change it to @SpringBootTest
it works.
@DataJpaTest
only loads the JPA part of a Spring Boot application. In the JavaDoc:
Annotation that can be used in combination with
@RunWith(SpringRunner.class)
for a typical JPA test. Can be used when a test focuses only on JPA components. Using this annotation will disable full auto-configuration and instead apply only configuration relevant to JPA tests.By default, tests annotated with
@DataJpaTest
will use an embedded in-memory database (replacing any explicit or usually auto-configured DataSource). The@AutoConfigureTestDatabase
annotation can be used to override these settings. If you are looking to load your full application configuration, but use an embedded database, you should consider@SpringBootTest
combined with@AutoConfigureTestDatabase
rather than this annotation.