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

无法到达控制器中的endpoint,尽管它已初始化

宋嘉懿
2023-03-14

我读了这个和这个,主要的想法是,有人有错误的结构和组件没有被扫描,我有一个正确的。

我的控制器正在正常初始化。我在Contructor上调试和设置断点进行了测试。它正在北京运行。尽管我的测试、邮递员和浏览器都无法到达endpoint。我得到的是404。我在用Gradle。我的代码是这样结构的。已经花了3个小时试图解决这个问题,但没有成功。

package com.fressnapf.microservices.orderhistory.controller.impl;

@RestController
@RequestMapping("/customer")
public class OrderHistoryController implements IOrderHistoryController {
    ...
    @Override
    @ResponseStatus(value = HttpStatus.OK)
    @RequestMapping(value = "/{customerid}/orders}", method = RequestMethod.GET, produces = "application/json")
    public String getOrders(@PathVariable("customerid") String customerid, @RequestParam(required = false) String timeFrom,
                        @RequestParam(required = false) String timeTo, @RequestParam(required = false) String openOnly) {
        ...
    }
}
package com.fressnapf.microservices.orderhistory;

@SpringBootApplication()
@ImportResource({"classpath*:applicationContext.xml"})
@Configuration()
public class Application {
public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
{
"timestamp": "2020-03-03T16:00:33.489+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/customer/000000000/orders"
}
    2020-03-03 16:59:27.595  INFO 10406 --- [           main] c.f.m.orderhistory.Application           : Starting Application on debian-sgtechedge with PID 10406 (/home/sergeygerodes/projects/scporderhistoryservice/build/classes/java/main started by sgerodes in /home/sergeygerodes/projects/scporderhistoryservice)
    2020-03-03 16:59:27.602  INFO 10406 --- [           main] c.f.m.orderhistory.Application           : No active profile set, falling back to default profiles: default
    2020-03-03 16:59:28.414  INFO 10406 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
    2020-03-03 16:59:28.441  INFO 10406 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 0 JPA repository interfaces.
    2020-03-03 16:59:28.768  INFO 10406 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2020-03-03 16:59:29.035  INFO 10406 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
    2020-03-03 16:59:29.046  INFO 10406 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2020-03-03 16:59:29.047  INFO 10406 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
    2020-03-03 16:59:29.140  INFO 10406 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2020-03-03 16:59:29.140  INFO 10406 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1475 ms
    2020-03-03 16:59:29.294  INFO 10406 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
    2020-03-03 16:59:29.405  INFO 10406 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
    2020-03-03 16:59:29.424  INFO 10406 --- [           main] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:orderhistory'
    2020-03-03 16:59:29.517  INFO 10406 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
    2020-03-03 16:59:29.565  INFO 10406 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.4.9.Final}
    2020-03-03 16:59:29.660  INFO 10406 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
    2020-03-03 16:59:29.741  INFO 10406 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
    2020-03-03 16:59:29.886  INFO 10406 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
    2020-03-03 16:59:29.892  INFO 10406 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
    2020-03-03 17:00:28.614  WARN 10406 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=59s108ms538?s586ns).
    2020-03-03 17:00:28.685  WARN 10406 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
    2020-03-03 17:00:28.845  INFO 10406 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-03-03 17:00:29.052  INFO 10406 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
    2020-03-03 17:00:29.060  INFO 10406 --- [           main] c.f.m.orderhistory.Application           : Started Application in 61.937 seconds (JVM running for 62.493)
    2020-03-03 17:00:33.395  INFO 10406 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
    2020-03-03 17:00:33.395  INFO 10406 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
    2020-03-03 17:00:33.404  INFO 10406 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 9 ms

整个ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="loggerService"
          class="com.fressnapf.sdk.logger.service.impl.DefaultLogService" />

    <bean id="dataService"
          class="com.fressnapf.sdk.dataaccess.services.impl.H2DataProvider">
        <constructor-arg index="0" value="${spring.datasource.url}"/>
        <constructor-arg index="1" value="${spring.datasource.username}"/>
        <constructor-arg index="2" value="${spring.datasource.password}"/>
    </bean>

</beans>

共有1个答案

董凡
2023-03-14

如果你复制了控制器代码粘贴在这里...有一个封闭的括号太多了。我在我的一个控制器上测试了它,它显示了相同的行为。

@RequestMapping(value = "/{customerid}/orders-->}<--"...
 类似资料:
  • 为了好玩,我一直在用java、javafx和scene builder做一个自己的项目。不幸的是,我遇到了一个无法修复的问题。我有一个名为“Homepage”的fxml文件和一个名为HomepageController的控制器。当我运行程序时,它会给我一个错误“java”。lang.ClassNotFoundException:HomepageController’。我使用的是MVC架构,我的FX

  • 问题内容: 我想延迟控制器的初始化,直到从服务器收到必要的数据为止。 我找到了针对Angular1.0.1的解决方案:延迟AngularJS路由更改,直到加载模型以防止闪烁,但无法使其与Angular1.1.0一起使用 模板 ​ JavaScript http://jsfiddle.net/dTJ9N/1/ 问题答案: 由于$ http返回了promise,因此创建自己的deferred仅在htt

  • 问题内容: 如果您有一个控制器来操作Angular.js中的$ scope变量,是否有惯用的方法: 重置控制器的$ scope,然后 重新启动控制器初始化? 对于复杂的控制器,不必将每个变量都重置为其初始值将非常方便,特别是如果您真正想要的是对控制器和范围进行简单的重新初始化。通过再次导航到相同的URL 并没有帮助。 编辑:假设我不能使用任何黑客工具,因为这会违反Chrome打包应用中的CSP。

  • 我成功地将“libmynative.so”文件夹复制到armeabi文件夹 但我仍然得到以下错误 这是我的主要活动 }

  • 本文向大家介绍IOS初始化控制器的实现方法总结,包括了IOS初始化控制器的实现方法总结的使用技巧和注意事项,需要的朋友参考一下 IOS初始化控制器的实现方法总结 一.ViewControllViewController方法 二 .ViewControllViewController 与 xib方法 如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

  • 我有一台有Windows操作系统的机器,它被用来构建很少的战争项目。它安装了Java8。我正在使用Maven 3.2.5构建这些WAR项目。一切都很好。但是由于Java8免费更新的结束,将来会成为一个问题,我想到了升级到OpenJDK11。 我下载了OpenJDK11,但没有安装它,因为我只是想尝试这个项目的1开始。我拿起一个WAR项目来检查OpenJDK11是否工作。这个项目是使用JHipste