2017-04-01 85 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顯然你試過的所有東西都是不正確的,因爲它會運行。你配置了錯誤的東西....順便說一句,它也適用於我... –