我正在尝试运行Spring Boot REST API应用程序,但出现404错误。
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>
我也尝试过@ComponentScan(basePackageClasses = HelloController.class)
,
但没有运气。您能帮忙解决这个问题吗?
如果我点击http://localhost:8080/hello网址,那么我会得到404。