1. 程式人生 > >springboot請求controller返回Whitelabel Error Page

springboot請求controller返回Whitelabel Error Page

解決的辦法: 
1、把自建的controller類放到啟動類同一級目錄下(不建議這樣做)。

2、把啟動類@RestController @EnableAutoConfiguration註解改成@SpringBootApplication。

3、啟動類@RestController @EnableAutoConfiguration註解再加上@ComponentScan註解。

使用springboot掃描的兩種註解配置方式: 
1、@Controller 
  @EnableAutoConfiguration 
  @ComponentScan

2、@SpringBootApplication

總結:@SpringBootApplication註解等價於以預設屬性使用@Configuration,@EnableAutoConfiguration和@ComponentScan

引用https://blog.csdn.net/Fandly168/article/details/73302281

發現問題還是沒解決,後方法上加入@ResponseBody後成功返回資料,但是資料是json型別

因為我這個專案只是提供服務,所以我的已經解決,但是考慮到以後可能要返回頁面,就找了下原因

/**
 * pom.xml檔案
 */
<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>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

檢視pom是否少了這些包,就可以解決不加@ResponseBody也能訪問的問題