spring boot 创建web应用时请求URL无法访问的问题

J2EE 码拜 8年前 (2016-05-31) 1456次浏览

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(MyApplication.class, args);
}
}

@Controller
@RequestMapping(“/test”)
public class TestController {
@RequestMapping(“/helloWorld”)
public String helloWorld(){
return “helloWorld!”;
}
}

pom.xml
<properties>
<!– dependencies –>
<spring.boot.version>1.3.3.RELEASE</spring.boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

请求URL http://localhost:8080/test/helloWorld

error message:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jun 16 15:31:08 CST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
解决方案

40

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp,
这是官网的例子,git下下来之后 ,用mvn命令启动 srping-boot:run就可以了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明spring boot 创建web应用时请求URL无法访问的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)