简体   繁体   English

Spring 使用 Derby 引导 Rest API 404 错误

[英]Spring Boot with Derby Rest API 404 Error

created simple spring boot rest api with gradle build tool使用 Z8ED1A771BC236C287ZAD93C699BFDD2 创建了简单的 spring 引导 rest api

package com.example.demosb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemosbApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemosbApplication.class, args);
    }   

}

my controller class我的 controller class

package com.example.demosb;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class demoSbController {
    
    @GetMapping("/welcome")
    public ResponseEntity<String> welcome() {
        return ResponseEntity.ok("Welcome To demo !");
    }

}

dependencies in build.gradle build.gradle 中的依赖项

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
runtimeOnly 'org.apache.derby:derby'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-security'

on url: http://localhost:8888 a login page is shown where i provide username:user and password is the, which leads to 404 error as there is no request mapping on path "/" that is ok在 url: http://localhost:8888 上显示登录页面,其中我提供用户名:用户和密码是,这导致 404 错误,因为路径“/”上没有请求映射是可以的

but for url: http://localhost:8888/welcome, still getting 404 error where expected is response entity json object with message: "Welcome To demo !" but for url: http://localhost:8888/welcome, still getting 404 error where expected is response entity json object with message: "Welcome To demo !"

In dependencies added is JPA and Derby.在依赖项中添加了 JPA 和 Derby。 Delete them and see if it works now.删除它们,看看它现在是否有效。 The connection to the database must be configured.必须配置与数据库的连接。

it worked for now, will be replying progress on this它现在有效,将回复这方面的进展

in my build.gradle, excluded tomcat related dependency from spring-web dependency and from configurations.all task as wanted to use jetty as embedded server在我的 build.gradle 中,从 spring-web 依赖项和配置中排除了 tomcat 相关的依赖项。所有任务都希望使用码头作为嵌入式服务器

...
implementation('org.springframework.boot:spring-boot-starter-web')
{
   exclude module: 'spring-boot-starter-tomcat'
}
...
configurations.all {
  exclude module: 'spring-boot-starter-tomcat'
  exclude group: 'org.apache.tomcat'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM