gla-rad / SECOMLib

A Java library facilitating the development of SECOM-compliant web interfaces
Apache License 2.0
8 stars 3 forks source link

JaxrsApplication not picked up #2

Closed cjmoeller closed 1 year ago

cjmoeller commented 1 year ago

When following the README.md using Spring Boot 3, the JaxrsApplication (inside the library) is not picked up by Resteasy/Spring. The CapabilitySecomInterface is instantiated as a Spring Component, but not recognised as a provider. It seems that RestEasy is not called at all.

cjmoeller commented 1 year ago

This seems to be some dependency issue as replacing the resteasy-spring-starter with


<dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-servlet-spring-boot-starter</artifactId>
            <version>6.0.4-SNAPSHOT</version>
            <scope>runtime</scope>
        </dependency>

solved the problem for my own implementation of the JaxrsApplication

nvasta commented 1 year ago

The modules are actually using the following dependency:

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

which seems a bit out of date...

Might not be a bad idea to use the resteasy-servlet-spring-boot-starter dependency but this kind of locks us tot he servlet flavour (as opposed to reactor netty).

nvasta commented 1 year ago

I've updated the library to use the resteasy-servlet-spring-boot-starter dependency. Also not that you will need to ad the spring-webflux dependency for the webClient.

Try using the version 0.0.21 artifacts and let me know if the problem was resolved.

cjmoeller commented 1 year ago

Setting up a clean spring project and importing the maven dependencies gives me the following error:

 :: Spring Boot ::                (v3.1.2)

2023-08-15T15:19:23.648+10:00  INFO 20969 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 20.0.1 with PID 20969 (/home/amsa/Desktop/demo/target/classes started by amsa in /home/amsa/Desktop/demo)
2023-08-15T15:19:23.652+10:00  INFO 20969 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2023-08-15T15:19:25.019+10:00  INFO 20969 --- [           main] o.j.r.s.common.ResteasyResourcesFinder   : Finding JAX-RS Application classes
2023-08-15T15:19:25.022+10:00  INFO 20969 --- [           main] o.j.r.s.common.ResteasyResourcesFinder   : Property resteasy.jaxrs.app.registration has not been set, JAX-RS Application classes registration is being set to AUTO
2023-08-15T15:19:25.023+10:00  INFO 20969 --- [           main] o.j.r.s.common.ResteasyResourcesFinder   : Searching for JAX-RS Application Spring beans
2023-08-15T15:19:25.026+10:00  INFO 20969 --- [           main] o.j.r.s.common.ResteasyResourcesFinder   : JAX-RS Application class found: org.grad.secom.springboot3.config.JaxrsApplication
2023-08-15T15:19:25.045+10:00  WARN 20969 --- [           main] o.j.r.s.common.ResteasyResourcesFinder   : No JAX-RS resource Spring beans have been found
2023-08-15T15:19:25.047+10:00  WARN 20969 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'org.grad.secom.springboot3.config.JaxrsApplication' defined in null: Cannot register bean definition [Generic bean: class [null]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=false; primary=false; factoryBeanName=JaxrsApplicationServletBuilder; factoryMethodName=build; initMethodNames=null; destroyMethodNames=null] for bean 'org.grad.secom.springboot3.config.JaxrsApplication' since there is already [Generic bean: class [org.grad.secom.springboot3.config.JaxrsApplication]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null] bound.
2023-08-15T15:19:25.063+10:00  INFO 20969 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-08-15T15:19:25.091+10:00 ERROR 20969 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'org.grad.secom.springboot3.config.JaxrsApplication' could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

Process finished with exit code 1
nvasta commented 1 year ago

Are you defining a JaxrsApplication component manually on your app?

nvasta commented 1 year ago

Also I would suggest to try and use the LTS JDK 17... next LTS version being 21... I see you are using 20.0.1. I usually prefer the LTS versions

cjmoeller commented 1 year ago

This was fixed in v0.0.23

nvasta commented 1 year ago

Just as a comment to keep track, the actual fix was annotating of the JaxRsApplication of the library as a configuration instead of a component. Otherwise it seems that the "resteasy-spring-boot-starter" attempts to create its own component and we get that conflicts. I was getting away with it using a package base scan but what's the point!