vaadin / quarkus

An extension to Quarkus to support Vaadin Flow
Apache License 2.0
28 stars 3 forks source link

Extension quarkus-spring-data-jpa not working #65

Closed lamemind-ud closed 2 years ago

lamemind-ud commented 2 years ago

Description of the Bug

Hello, I cloned this repository and tried to integrate some functions, but I'm stuck with database access.

What i want to do

I'd like to use Spring repositories (org.springframework.data.repository.*) just like I already do in other Quarkus projects, throught the quarkus-spring-data-jpa extension.

Stack trace

java.lang.IllegalArgumentException: Producer method return type not found in index: org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations

$ .\mvnw
[..]

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running it.ufficiodiscount.ExampleResourceTest
Downloading from vaadin-prereleases: https://maven.vaadin.com/vaadin-prereleases/org/webjars/npm/mobile-drag-drop/maven-metadata.xml
2022-02-20 17:53:05,142 WARN  [io.qua.hib.orm.dep.HibernateOrmProcessor] (build-25) Could not find a suitable persistence unit for model classes:
        - io.quarkus.hibernate.orm.panache.PanacheEntity
        - io.quarkus.hibernate.orm.panache.PanacheEntityBase
2022-02-20 17:53:05,344 WARN  [io.qua.arc.pro.BeanArchives] (build-25) Failed to index org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: TEST@6686
3941
2022-02-20 17:53:05,345 INFO  [io.qua.arc.pro.IndexClassLookupUtils] (build-25) Class for name: org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations was not found in Jandex index. Please ensure the class is part of the index.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.099 s <<< FAILURE! - in it.ufficiodiscount.ExampleResourceTest
[ERROR] it.ufficiodiscount.ExampleResourceTest.testHelloEndpoint  Time elapsed: 0.006 s  <<< ERROR!
java.lang.RuntimeException:
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#registerBeans threw an exception: java.lang.IllegalArgumentException: Producer method return type not found in index: org.springframework.boot.autoconfigure.web.servlet.WebMvcRegist
rations
        at io.quarkus.arc.processor.Types.getProducerMethodTypeClosure(Types.java:245)
        at io.quarkus.arc.processor.Beans.createProducerMethod(Beans.java:236)
        at io.quarkus.arc.processor.BeanDeployment.findBeans(BeanDeployment.java:1020)
        at io.quarkus.arc.processor.BeanDeployment.registerBeans(BeanDeployment.java:233)
        at io.quarkus.arc.processor.BeanProcessor.registerBeans(BeanProcessor.java:120)
        at io.quarkus.arc.deployment.ArcProcessor.registerBeans(ArcProcessor.java:380)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Caused by: java.lang.RuntimeException:
io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#registerBeans threw an exception: java.lang.IllegalArgumentException: Producer method return type not found in index: org.springframework.boot.autoconfigure.web.servlet.WebMvcRegist
rations
        at io.quarkus.arc.processor.Types.getProducerMethodTypeClosure(Types.java:245)
        at io.quarkus.arc.processor.Beans.createProducerMethod(Beans.java:236)
        at io.quarkus.arc.processor.BeanDeployment.findBeans(BeanDeployment.java:1020)
        at io.quarkus.arc.processor.BeanDeployment.registerBeans(BeanDeployment.java:233)
        at io.quarkus.arc.processor.BeanProcessor.registerBeans(BeanProcessor.java:120)
        at io.quarkus.arc.deployment.ArcProcessor.registerBeans(ArcProcessor.java:380)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Caused by: io.quarkus.builder.BuildException:
Build failure: Build failed due to errors
        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#registerBeans threw an exception: java.lang.IllegalArgumentException: Producer method return type not found in index: org.springframework.boot.autoconfigure.web.servlet.WebMvcRegist
rations
        at io.quarkus.arc.processor.Types.getProducerMethodTypeClosure(Types.java:245)
        at io.quarkus.arc.processor.Beans.createProducerMethod(Beans.java:236)
        at io.quarkus.arc.processor.BeanDeployment.findBeans(BeanDeployment.java:1020)
        at io.quarkus.arc.processor.BeanDeployment.registerBeans(BeanDeployment.java:233)
        at io.quarkus.arc.processor.BeanProcessor.registerBeans(BeanProcessor.java:120)
        at io.quarkus.arc.deployment.ArcProcessor.registerBeans(ArcProcessor.java:380)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Caused by: java.lang.IllegalArgumentException: Producer method return type not found in index: org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors: 
[ERROR]   ExampleResourceTest.testHelloEndpoint » Runtime java.lang.RuntimeException: io...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.036 s
[INFO] Finished at: 2022-02-20T17:53:05+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project base-starter-flow-quarkus: There are test failures.
[ERROR]
[ERROR] Please refer to C:\local\work\clienti\shadow-ufficiodiscount\code\-tests\live-view\base-starter-flow-quarkus\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

How to reproduce

In order to reproduce just add the quarkus-spring-data-jpa dependency.

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-spring-data-jpa</artifactId>
        </dependency>

quarkus version 2.5.4.Final vaadin version 22.0.2

Thanks

mstahv commented 2 years ago

Hi @lamemind-ud !

Do you have some data source set up in the project? Based on the error I'd guess that might be the problem.

lamemind-ud commented 2 years ago

Hello @mstahv and thanks for you response, but it's not a datasource related problem.

I'm not extending Panache, I'm using base entities

@Entity
@Table(name = "Brand")
public class Brand {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Integer id;
[..]

Step to reproduce the error

quarkus.hibernate-orm.packages=org.demo

quarkus.datasource.db-kind=h2
quarkus.datasource.username=sa
quarkus.datasource.password=password
quarkus.datasource.jdbc.url=jdbc:h2:mem:quarkus_test;DB_CLOSE_DELAY=-1
quarkus.hibernate-orm.database.generation=create
quarkus.hibernate-orm.log.sql=true

Expected result: the unit test should work Result: the unit test fails with the stack trace reported in my previous comment

Idk if it's useful, but if you remove vaadin-core-jandex dependency, the test works. And of course the app crashes as soon as you load localhost:8080 and this is expected to crash.

Thanks again

mstahv commented 2 years ago

Sounds weird. Maybe there is something extra in the vaadin-core-jandex that should not be there 🤔

Could you share that project somehow? zip it and attach it to this issue, or share it in GitHub. That would really help our core team to look into it (and this way increase the chances that they would look into it sooner).

lamemind-ud commented 2 years ago

Sounds weird. Maybe there is something extra in the vaadin-core-jandex that should not be there 🤔

Could you share that project somehow? zip it and attach it to this issue, or share it in GitHub. That would really help our core team to look into it (and this way increase the chances that they would look into it sooner).

@mstahv I'll share the full project tomorrow

lamemind-ud commented 2 years ago

Hello,

I just uploaded the project as requested. vaadin-quarkus-bug.zip

Cheers

lamemind-ud commented 2 years ago

PS: in the uploaded project, I have already commented out the vaadin-core-jandex dependency. You have to remove the comment in order to reproduce the bug. Sorry for the confusion

mstahv commented 2 years ago

Thanks that helps a lot! Our core team promised to investigate this in their next sprint.

mcollovati commented 2 years ago

Seems like that adding quarkus-spring-data-jpa causes bean discovery of fusion configuration classes, but fusion-endpoint has provided scope for some spring dependency, including spring-boot-autoconfigure that contains org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations.

@lamemind-ud if you don't need fusion endpoint in your project, can you try adding the following configuration to application.properties?

quarkus.arc.exclude-types=com.vaadin.fusion.*
lamemind-ud commented 2 years ago

Hello @mcollovati , your workaround is working! The unit test succeeded and the web app has started!

Actually I don't know what fusion-endpoint is... I'm very new to vaadin. And what if I need fusion-endpoint in the future?

mstahv commented 2 years ago

You don't need that. It will also not be included on the classpath by default in the future.

mcollovati commented 2 years ago

Vaadin 23 and Vaadin 22.0.7 (and later) will exclude fusion stuff from jandex index, so there will be no need for additional settings in application.properties