2017-09-30 31 views
0

在我的春天啓動的應用程序404錯誤,我有以下pom.xml彈簧引導錯誤:在加載模板

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

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

的控制器我有如下簡單的一個:

@Controller 
    public class ThyemeleafController { 

     @RequestMapping("/") 
     public String home() { 
      return "home"; 
     } 
    } 

然後我有一個簡單的home.htmlsrc/main/resources/templates其中包含helloWorld。但是當我運行的應用程序並進入網址:

Whitelabel Error Page 

This application has no explicit mapping for /error, so you are seeing this as a fallback. 

Fri Sep 29 17:15:13 GMT-12:00 2017 
There was an unexpected error (type=Not Found, status=404). 
No message available 

回答

-1

我有我的回答是:

http://localhost:8080/ 

它抱怨。我在另一個包寫了我的控制器,從而,我要問的春天開機掃描該包裹並從中基本豆:

@SpringBootApplication 
@ComponentScan("com.eventer.controller") 
public class DemoApplication { 

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

你不需要@ComponentScan(「com.eventer.controller」)與春季啓動。 –

+0

那麼,它是如何解決我的問題? –

+0

您必須遵循Java推薦的包命名約定。 https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html –