当前位置: 首页 > 知识库问答 >
问题:

Spring boot 2.1.0版本获取404未找到错误

岳均
2023-03-14

我一直试图在2.1.0版本中运行Spring引导。我得到404错误,即使试图访问localhost:8080。我已经修改了所有的控制器,服务在同一个主包,但没有运气。任何帮助都很感激。下面是我的控制台日志...甚至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);
    }
}

控制器类:

    @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);
        }

共有1个答案

寿丰
2023-03-14

似乎Spring没有读取您的控制器,这似乎是一个结构问题。请考虑下面的变化:

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


    @Autowired
    private MobilityService mobilityService;

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

要使用restendpoint,请尝试访问localhost:8080/your_decise/mobilityCC

编辑:

确保您具有SpringWeb依赖项。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>${spring-boot.version}</version>
    </dependency>
 类似资料:
  • 你好,我试图学习野蝇和springboose一个非常简单的应用程序使用eclipse。项目名称是springboo-test。包括主方法类在内的所有类都在同一个包中。 主方法类称为'App',其代码如下: 以下是服务器日志: 11:36:57281信息[org.wildfly.extension.undertow](服务器服务线程池--68)WFLYUT0021:注册的web上下文:'/sprin

  • 我正在尝试(失败)设置一个简单的FastAPI项目,并使用uvicorn运行它。这是我的代码: 这是我从终端运行的内容: 如你所见,我找不到404。原因可能是什么?一些与网络相关的东西,可能是防火墙/vpn阻止此连接或其他什么?我是新来的。提前谢谢!

  • 使用postman,我访问keycloak api方法进行推理,以避免在我的angular应用程序中将key cloak页面作为登录页面。我从属于主域的域中获取access_token,但在访问另一个域(为特定于angular应用程序创建)时,将token作为授权承载token我的请求,得到404 not found错误。 从主域获取access_token 使用承载令牌访问其他领域

  • 在过去的几天里,我一直在做一个Camel和REST DSL的基本演示,但最终我遇到了这个问题。我对Spring Boot的魔力还比较陌生,所以非常感谢您的反馈! 当我运行项目时,我的两条路由的一切看起来都正确启动。但是,当我尝试GET请求时,我总是会收到404“未找到”消息。 我仅有的两个类在同一个包中,所以我不认为可见性会是问题。我将该项目创建为Spring Start项目,并将其作为Sprin

  • 问题内容: 在ubuntu 15.10上执行eiskaltdc ++时,出现以下错误: 我能够使用Qt Creator成功地编译应用程序。 编辑 运行ldd给了我这个。我不确定如何解释这个 请提出解决方案。谢谢。 问题答案: 发生问题是因为您从发行版中安装了Qt,而ld将默认使用它。为避免此类问题,您可以编译或一起使用以帮助链接器找到所需的Qt版本。

  • Traceback(最近的最后一次调用):文件"C:/用户/AppData/本地/程序/Python/Python37/client.py",第54行,引号=json.loads(urllib.request.urlopen(QUERY.格式(random.random())). read())文件"C:\用户\AppData\本地\程序\Python\Python37\lib\urllib\re