簡體   English   中英

Spring不掃描軟件包

[英]Spring doesn't scan packages

我有一個存儲庫,帶有@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); } } 

而且我不斷收到這個錯誤

***************************申請無法開始


描述:

com.jeppa.controllers.UserAccountController中的字段userRepository要求找不到類型為“ com.jeppa.interfaces.UserRepository”的bean。

注入點具有以下注釋:-@ org.springframework.beans.factory.annotation.Autowired(required = true)

行動:

考慮在配置中定義類型為“ com.jeppa.interfaces.UserRepository”的bean。

我究竟做錯了什么? 這是我的項目結構: 結構

使用Spring Boot,通常應該依靠Spring Boot啟動器來自動配置依賴項。 如果是Spring Data,請添加:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

放入pom文件以自動配置Spring Data,而不是直接依賴Spring Data( spring-data-jpa ),這需要進一步的手動配置。

同樣不要忘記添加和配置實際的實現(h2,jdbc等)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM