2017-04-01 87 views
0

我试图运行一个弹簧启动应用程序。我从教程中下载了一段代码,所以我知道代码的作用。当我运行我的jar文件时,它看起来像我在端口8080上运行的应用程序,但我仍然得到404的任何URL,我从来没有得到春白标签页。我检查了我没有运行任何其他端口8080,并启动并运行了服务器。启动jar时弹簧启动错误404

我不知道为什么我的应用程序没有响应。

running the jar

error 404

package com.virtualpairprogrammers; 

import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

/** 
* Created by masn on 2017-04-01. 
*/ 

@RestController 
public class HelloController { 

    @RequestMapping("/hello") 
    public String sayHello(){ 
     return "Hello"; 
    } 
} 


enter code here 

包com.virtualpairprogrammers;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication 公共类FleetmanApplication {

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

}

enter code here 

http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0 .0

<groupId>com.virtualpairprogrammers</groupId> 
<artifactId>fleetman</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>fleetman</name> 
<description>VPP´s Fleet Management Application</description> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.2.RELEASE</version> 
    <relativePath/> <!-- lookup parent from repository --> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

+0

嗯,至少我应该得到的白色标签页?是的,我尝试添加控制器.... –

+0

对不起。现在检查,没有做任何设置,并按照教程,它在视频100%相同的指示。 –

+0

那么在vidoe中,他明确指出,默认是任何请求类型,并且没有任何方法适用于他。 –

回答

0

刚刚尝试这样,它会工作:

@RestController 
public class HelloController { 

    @RequestMapping(path = "/hello", method = RequestMethod.GET) 
    public String hello() { 
     return "hello"; 
    } 
} 

这里的截图,我从我的电脑采取: Working Controller

+0

这是屈辱,但不适用于我.....所以它必须是计算机特定的问题 –

+0

显然,我尝试的所有内容都是正确的,我想我会重新格式化我的电脑,然后重试。 –

+0

Mattias显然你试过的所有东西都是不正确的,因为它会运行。你配置了错误的东西....顺便说一句,它也适用于我... –