No found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
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:
- Annotate
UserDaoImpl
with@Component
or@Repository
, and let the component scan do the work for you, exactly as you have done withUserService
. - Add the bean manually to your xml file, the same you have done with
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.
Add the annotation @Repository
to the implementation of UserDaoImpl
@Repositorypublic class UserDaoImpl implements UserDao { private static Log log = LogFactory.getLog(UserDaoImpl.class); @Autowired @Qualifier("sessionFactory") private LocalSessionFactoryBean sessionFactory; //...}
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.