java - Spring Boot 2.1.0 发布出现 404 not found 错误

标签 java spring spring-boot

我一直在尝试在2.1.0版本中运行spring boot。即使尝试访问 localhost:8080,我也会收到 404 错误。我已经修改了所有 Controller ,在同一个主包中提供服务,但没有运气。任何帮助表示赞赏。下面是我的控制台日志..甚至 localhost:8080 也不起作用。

    <pre>
     [INFO] Scanning for projects...
    [INFO] 
    [INFO] ------------------------------------------------------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] >>> spring-boot-maven-plugin:2.1.0.RELEASE:run (default-cli) > test-compile @ demo >>>
    [WARNING] The POM for ojdbc:ojdbc:jar:6 is missing, no dependency information available
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ demo ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory C:\demo\demo\src\test\resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ demo ---
    [INFO] No sources to compile
    [INFO] 
    [INFO] <<< spring-boot-maven-plugin:2.1.0.RELEASE:run (default-cli) < test-compile @ demo <<<
    [INFO] 
    [INFO] 
    [INFO] --- spring-boot-maven-plugin:2.1.0.RELEASE:run (default-cli) @ demo ---
     Spring Boot ::        (v2.1.0.RELEASE)

    2018-11-01 16:56:39.864  INFO 13552 --- [           main] com.DemoApplication          : Starting DemoApplication on  (C:\demo\demo\target\classes started by mine in C:\demo\demo)
    2018-11-01 16:56:39.872  INFO 13552 --- [           main] com.DemoApplication          : No active profile set, falling back to default profiles: default
    2018-11-01 16:56:41.492  INFO 13552 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
    2018-11-01 16:56:41.666  INFO 13552 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 159ms. Found 1 repository interfaces.
    2018-11-01 16:56:42.989  INFO 13552 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
    2018-11-01 16:56:43.069  INFO 13552 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2018-11-01 16:56:43.070  INFO 13552 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.12
    2018-11-01 16:56:43.096  INFO 13552 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_131\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_144/bin/server;C:/Program Files/Java/jre1.8.0_144/bin;C:/Program Files/Java/jre1.8.0_144/lib/amd64;C:\app\mine\product\11.2.0\client_1\bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\app\mine\product\11.2.0\client_1;C:\Program Files\Java\jdk1.8.0_131\bin;C:\Software\apache-maven-3.5.2-bin\apache-maven-3.5.2\bin;C:\ProgramData\Oracle\Java\javapath;C:\app\mine\product\11.2.0\client\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Symantec\Workspace Streaming\bin\;C:\Program Files\Symantec\Workspace Virtualization\;C:\Program Files\TortoiseSVN\bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Program Files\1E\NomadBranch\;C:\Program Files\Common Files\ThinPrint\;C:\Program Files\nodejs\;C:\Users\mine\AppData\Roaming\npm;C:\Windows\system32;;.]
    2018-11-01 16:56:43.402  INFO 13552 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/h]      : Initializing Spring embedded WebApplicationContext
    2018-11-01 16:56:43.402  INFO 13552 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3419 ms
    2018-11-01 16:56:43.496  INFO 13552 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
    2018-11-01 16:56:43.916  INFO 13552 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
    2018-11-01 16:56:45.002  INFO 13552 --- [           main] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
    2018-11-01 16:56:45.040  INFO 13552 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
    2018-11-01 16:56:45.189  INFO 13552 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
    2018-11-01 16:56:45.371  INFO 13552 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.7.Final}
    2018-11-01 16:56:45.375  INFO 13552 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
    2018-11-01 16:56:45.791  INFO 13552 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
    2018-11-01 16:56:46.235  INFO 13552 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
    2018-11-01 16:56:49.137  INFO 13552 --- [           main] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
    2018-11-01 16:56:49.314  INFO 13552 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
    2018-11-01 16:56:50.878  INFO 13552 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/h'
    2018-11-01 16:56:50.881  INFO 13552 --- [           main] com.DemoApplication          : Started DemoApplication in 13.048 seconds (JVM running for 25.664)



    </pre>

**Main class:**

@SpringBootApplication
public class DemoApplication {

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

Controller 类:

    @RestController
    public class MobilityApi {


        @Autowired
        private MobilityService mobilityService;

        @RequestMapping(method=RequestMethod.GET,value="/mobilityCC")
        public Response retrieveOrderDetails(@QueryParam("orderid") String orderid) {
            return mobilityService.getOrderDetails(orderid);
        }

最佳答案

Spring 似乎没有读取你的 Controller ,这似乎是一个结构问题。 请考虑进行以下更改:

@RestController
@RequestMapping("/your_decide/")
public class MobilityApi {


    @Autowired
    private MobilityService mobilityService;

    @GetMapping("/mobilityCC")
    public Response retrieveOrderDetails(@RequestParam("orderid") String orderid) {
        return mobilityService.getOrderDetails(orderid);
    }
}

并且,您的主类必须位于根文件夹中。像这样的东西: enter image description here

要使用其余端点,请尝试访问localhost:8080/your_decide/mobilityCC

编辑:

确保您具有 spring-web 依赖项。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>${spring-boot.version}</version>
    </dependency>

关于java - Spring Boot 2.1.0 发布出现 404 not found 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53100730/

相关文章:

java - Process.waitfor 会使服务/Activity 进入休眠状态还是会消耗 CPU?

java - 大约一半的用户在数据库更改后得到 `Bad Credentials`

java - 禁用 springframework 的日志记录

java - 为什么我的 Spring @Async bean 方法没有异步执行?

java - 无法解决此错误 : Failed to configure a DataSource

java - 无法运行 TestNG 或 JUnit 测试

java - 防止 Java 插件尝试下载 pack.gz 版本的存档

java - Thymeleaf 和 Spring MVC 的表单参数为 null

java - 如何使用 Optional.ifPresent 返回 boolean 值

spring-boot - 在 Thymeleaf 生成的 HTML 文档中包含 <image>