Код: Выделить всё
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userJpaRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.codejava.spring.repository.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userJpaRepository)}
Код: Выделить всё
@Controller
public class UserController {
private UserService employeeServiceImpl;
@RequestMapping("/")
public String employee() {
this.employeeServiceImpl.listAlUsers();
return "employee";
}
@Autowired(required = true)
public void setEmployeeService(UserService employeeServiceImpl) {
this.employeeServiceImpl = employeeServiceImpl;
}
}
Код: Выделить всё
public interface UserService {
public abstract List listAlUsers();
public abstract User addUser(User user);
public abstract int removeUser(int id);
public abstract User updateUser(User user);
}
Код: Выделить всё
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
@Qualifier("userJpaRepository")
private UserRepository userJpaRepository;
@Override
public List listAlUsers() {
return userJpaRepository.findAll();
}
@Override
public User addUser(User user) {
return userJpaRepository.save(user);
}
@Override
public int removeUser(int id) {
userJpaRepository.delete(id);
return 0;
}
@Override
public User updateUser(User user) {
return userJpaRepository.save(user);
}
}
Код: Выделить всё
@Repository("userJpaRepository")
public interface UserRepository extends JpaRepository {
}
Код: Выделить всё
contextConfigLocation
/WEB-INF/spring/root-context.xml
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/spring/appServlet/servlet-context.xml
1
appServlet
/
Код: Выделить всё
/WEB-INF/views/
.jsp
messages
Я не знаю, где возможная причина ошибки. попытайтесь найти разные варианты, но если я использую шаблон DAO, я получаю ту же ошибку, поэтому мне нужно знать, в чем проблема, чтобы попытаться ее решить.
конфигурация проекта выполнена в формате xml, но я думаю, что решать эту проблему не так уж и важно. ситуация.
С уважением!
Подробнее здесь: https://stackoverflow.com/questions/425 ... pressed-th