Reputation: 137
I am trying to run Spring Boot REST API application, but I am getting a 404 error.
package com.spring.boot.entry;
@SpringBootApplication
@ComponentScan(basePackageClasses = HelloController.class)
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
package com.spring.boot.entry.hello;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHello() {
return "Hi First Spring boot application ";
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.boot.quickstart</groupId>
<artifactId>course-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Boot API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
I also tried @ComponentScan(basePackageClasses = HelloController.class)
,
but no luck. Could you please help to resolve this issue?
If I hit http://localhost:8080/hello url then I am getting 404.
Upvotes: 3
Views: 9901
Reputation: 15423
I executed your code on my system and unless you've messed up with the directory structure it is working as expected. Cross check that once.
CourseApiApp.java
HelloController.java
Output
Upvotes: 4