日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

springboot启动后controller访问404

發布時間:2025/5/22 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot启动后controller访问404 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 首先需要在springboot的啟動類上面使用@SpringBootApplication注解,并且指定掃描的包的位置,如下:

    package com.example;

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

    @SpringBootApplication(scanBasePackages="com.example.controller")
    public class DemoApplication {

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

    }
    這里如過需要掃描多個包可以這么寫scanBasePackages={"com.xxx","com.xxx"}這種形式即可

  • 2.其次在當前的pom.xml中指定springboot啟動類:

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <!-- 這里是我本人的springboot啟動類位置,請根據自己的情況改動,idea下面可以點出來的-->
    <start-class>com.example.DemoApplication</start-class>
    </properties>
    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <fork>true</fork>
    <mainClass>${start-class}</mainClass>
    </configuration>
    </plugin>
    </plugins>
    </build>

    3.這里是我的controller:

    package com.example.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controller@RequestMapping("/home")public class TestController {@RequestMapping("/hello")@ResponseBodypublic String index(){return "hello world";}}

    注意:以上的springboot版本是2.0.5.RELEASE版,不同版本可能會有所不同。
    springboot啟動后瀏覽器輸入下面的URL即可
    http://localhost:8080/home/hello

    轉載于:https://blog.51cto.com/3440684/2299831

    總結

    以上是生活随笔為你收集整理的springboot启动后controller访问404的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。