2

I read this and this The main ideas are that somebody has the wrong structure and components are not beeing scanned, I have a correct one.

My controller is beeing initialised normaly. I tested it debugging and seting the breakpoint on the contructor. It is beiing runned. DEspite of the that the endpoint could not be reached by my tests nor by postman, nor in the browser. I am getting a 404. I am using gradle. structured my code like this. Already spent 3 Hours trying to fix this, but without success.

My controller looks like this.

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) {
        ...
    }
}

Aplplication class

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

this is the response I am getting

{
"timestamp": "2020-03-03T16:00:33.489+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/customer/000000000/orders"
}

this is the log I am getting in the app

    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

the whole 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>
SG Tech Edge
  • 477
  • 4
  • 16
  • What endpoint are you trying? Looks like you are in Linux; can you try (with the application running) `curl -X GET -H "Accept: application/json" http://localhost:8080/customer/10000001/orders` and paste what's the result for that command? – x80486 Mar 03 '20 at 16:19
  • @x80486 Yes, I am on linux. the response of curl is {"timestamp":"2020-03-03T16:20:17.520+0000","status":404,"error":"Not Found","message":"No message available","path":"/customer/10000001/orders"} – SG Tech Edge Mar 03 '20 at 16:20
  • It is basically the same request I am sending. You can see it in the "response" section of the question. – SG Tech Edge Mar 03 '20 at 16:24
  • That's weird, it should work, unless there is something else as part of the URL, which I can't see as on the startup messages...what's the content of `applicationContext.xml`? By the way, `@Configuration` in `Application` is doing nothing...you can remove it. Also paste your `application.y[a]ml` inside ../main/resources/`. – x80486 Mar 03 '20 at 16:26
  • @x80486 I have no application.yamls in my project... Where do you see them? Pasted in the description my applicationContext – SG Tech Edge Mar 03 '20 at 16:34
  • THats the thing. It also looks good for me. Removing the @RestController makes it not initialising the contrloler. I tested it manually. But the response is the same regardless of the it beeing initialised. It does not see the endpoint – SG Tech Edge Mar 03 '20 at 16:36

1 Answers1

3

If you copied your controller code and pasted it here... There is a close bracket too much. I tested it on one of my controllers and it shows the same behaviour.

@RequestMapping(value = "/{customerid}/orders-->}<--"...
kluckow
  • 181
  • 1
  • 4