我有一个存储库,注释为@ repository
package com.jeppa.interfaces;
import com.jeppa.entities.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends CrudRepository<User, String> {
User findByUserEmailIgnoreCase(String useremail);
}
我的控制器的一部分:
package com.jeppa.controllers;
import com.jeppa.entities.ConfirmationToken;
import com.jeppa.entities.User;
import com.jeppa.interfaces.TokenRepository;
import com.jeppa.interfaces.UserRepository;
import com.jeppa.mail.EmailSenderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class UserAccountController {
@Autowired
private UserRepository userRepository;
@Autowired
private TokenRepository tokenRepository;
@Autowired
private EmailSenderService emailSenderService;
@RequestMapping(value = "/register", method = RequestMethod.GET)
public ModelAndView displayRegistration(ModelAndView modelAndView, User user){
modelAndView.addObject("user", user);
modelAndView.setViewName("register");
return modelAndView;
}
//////////////
最后,我的@SpringBootApplication:
package com.jeppa;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RunApplication {
public static void main(String[] args) {
SpringApplication.run(RunApplication.class, args);
}
}
我一直在犯这个错误
*申请启动失败
描述:
字段userRepository在com.jeppa.controllers.UserAccountController中需要一个无法找到的'com.jeppa.interfaces.UserRepository‘类型的bean。
注入点有以下注释:- @org.springframework.beans.factory.annotation.Autowired(required=true)
操作:
考虑在您的配置中定义'com.jeppa.interfaces.UserRepository‘类型的bean。
我做错什么了?以下是我的项目结构:结构
发布于 2019-06-14 18:57:12
对于Spring,通常应该依赖Spring启动程序来自动配置依赖项。在Spring数据中添加:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>在pom文件中自动配置Spring数据,而不是直接依赖Spring (spring-data-jpa),这需要进一步的手动配置。
另外,也不要忘记添加和配置一个实际的实现(h2、jdbc等)。
https://stackoverflow.com/questions/56603584
复制相似问题