created simple spring boot rest api with gradle build tool
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
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
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
but for url : http://localhost:8888/welcome , still getting 404 error where expected is response entity json object with message : "Welcome To demo !"
CodePudding user response:
In dependencies added is JPA and Derby. Delete them and see if it works now. The connection to the database must be configured.
CodePudding user response:
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
...
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'
}