Hey!
Following situation:
There's a service interface UserService
..and the appropriate implementation UserServiceImplCode:public interface UserService { ... List<User> findAllUsers(); ... }
Now I try to write a JUnit test for my service implementation, it looks like this so far...Code:@Service public class UserServiceImpl implements UserService { @Autowired UserRepository userRepository; public List<User> findAllUsers() { return userRepository.findAll(); } ... }
But when I run the test, I get the following error:Code:public class UserServiceImplTest { @Autowired public UserService userService; ... }
The implentation und interface are within the same package, and I scan my path viaCode:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'net.twentyfourseven.blog.service.UserServiceImplTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public net.twentyfourseven.blog.service.UserService net.twentyfourseven.blog.service.UserServiceImplTest.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.twentyfourseven.blog.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Does anyones knows whats the problem here????Code:<context:component-scan base-package="net.twentyfourseven.blog" /> <context:annotation-config />
Thank you!
Markus


Reply With Quote