Java Spring启动应用程序问题
我正在开发一个spring boot/postgres应用程序。这是项目结构 src/main/javaJava Spring启动应用程序问题,java,spring,spring-boot,Java,Spring,Spring Boot,我正在开发一个spring boot/postgres应用程序。这是项目结构 src/main/java com.test.app com.test.app.controller com.test.app.model com.test.app.repository src/test/java com.test.app Eclipse抛出了一个编译错误,表示“没有类型为….repository的合格bean”。我必须在主课中加入以下注释。这里怎么了 @ComponentScan(basePac
com.test.app
com.test.app.controller
com.test.app.model
com.test.app.repository
src/test/java
com.test.app
Eclipse抛出了一个编译错误,表示“没有类型为….repository的合格bean”。我必须在主课中加入以下注释。这里怎么了
@ComponentScan(basePackages={“com.test.app.repository.AppRepository”})
而且,映射对我不起作用。我在控制器类中有以下注释
@RestController
@RequestMapping("/api")
它也是自动连接的存储库类。显示白色标签错误页面。有什么建议吗
@RestController
@RequestMapping("/api")
public class AppController {
@Autowired
AppRepository appRepository;
@PostMapping("/order")
public ResponseEntity<AppEntity> createOrder(@RequestBody AppEntity order) {
@GetMapping("/orders")
public ResponseEntity<List<AppEntity>> getAllOrder(@RequestParam(required = false) String name) {
@GetMapping("/order/{id}")
public ResponseEntity<AppEntity> getOrderById(@PathVariable("id") long id) {
@RestController
@请求映射(“/api”)
公共类AppController{
@自动连线
评价性评价性评价;
@邮购(“/订单”)
公共响应属性createOrder(@RequestBody外观顺序){
@GetMapping(“/orders”)
public ResponseEntity getAllOrder(@RequestParam(required=false)字符串名){
@GetMapping(“/order/{id}”)
公共响应属性getOrderById(@PathVariable(“id”)长id){
存储库类
@Repository
public interface AppRepository extends JpaRepository<AppEntity, Long>{
List<AppEntity> findByName(String name);
}
@存储库
公共接口附件扩展了JPA附件{
列出findByName(字符串名称);
}
检查应用程序属性文件中是否设置了任何上下文路径“server.servlet.contextPath=/”。由于没有代码,也没有任何好的提示,因此无法准确理解问题的具体内容和位置。请阅读一个问题,并提供示例。您是否有主类(使用@SpringBootApplicationIn)在com.test.app package下?com.test.app.repository.AppRepository
不是一个包,它是包中的一个类。(此外,如果必须指定存储库库库库库,您可能需要查找@EnableJpaRepositories
,因为存储库接口不是bean,而是运行时生成bean的指令。)是的,我确实在com.test.app下有一个主类。我怀疑这是一个编译错误,而是spring检查中的错误。其次,这不是来自eclipse的误报吗?您是否只是尝试运行该应用程序(不管错误如何)。