micronaut-projects / micronaut-discovery-client

Micronaut's Discovery Client
Apache License 2.0
22 stars 20 forks source link

Micronaut won't start (throws exception) when "discovery-client" feature is enabled #514

Closed tired-old-man closed 1 year ago

tired-old-man commented 1 year ago

Expected Behavior

The application should start.

Actual Behaviour

The BeanInstantiationException exception is thrown.

Stack trace:

19:20:06.684 [main] INFO  i.m.context.DefaultBeanContext - Reading bootstrap environment configuration
19:20:06.848 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [io.micronaut.discovery.eureka.EurekaServiceInstanceList] could
not be loaded: io/micronaut/http/client/HttpClientConfiguration
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [io.micronaut.discovery.eureka.EurekaServiceInstanceList] could not be loaded: io/micronaut/http/client/HttpClientConfiguration
        at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.getDefinition(DefaultBeanContext.java:4157)
        at io.micronaut.context.DefaultBeanContext.collectBeanCandidates(DefaultBeanContext.java:2138)
        at io.micronaut.context.DefaultBeanContext.findBeanCandidates(DefaultBeanContext.java:2113)
        at io.micronaut.context.DefaultBeanContext.findBeanCandidatesInternal(DefaultBeanContext.java:3362)
        at io.micronaut.context.DefaultBeanContext.getBeanRegistrations(DefaultBeanContext.java:3417)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:1436)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:881)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:871)
        at io.micronaut.context.event.ApplicationEventPublisherFactory$2.lambda$$1(ApplicationEventPublisherFactory.java:215)
        at io.micronaut.core.util.SupplierUtil$1.get(SupplierUtil.java:47)
        at io.micronaut.context.event.ApplicationEventPublisherFactory$2.publishEvent(ApplicationEventPublisherFactory.java:226)
        at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1779)
        at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:360)
        at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:198)
        at io.micronaut.runtime.Micronaut.start(Micronaut.java:73)
        at io.micronaut.runtime.Micronaut.run(Micronaut.java:322)
        at io.micronaut.runtime.Micronaut.run(Micronaut.java:308)
        at foo.Application.main(Application.java:8)
Caused by: java.lang.NoClassDefFoundError: io/micronaut/http/client/HttpClientConfiguration
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at io.micronaut.discovery.eureka.$EurekaServiceInstanceList$Definition.<clinit>(Unknown Source)
        at io.micronaut.discovery.eureka.$EurekaServiceInstanceList$Definition$Reference.load(Unknown Source)
        at io.micronaut.context.AbstractInitializableBeanDefinitionReference.load(AbstractInitializableBeanDefinitionReference.java:178)
        at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.getDefinition(DefaultBeanContext.java:4152)
        ... 17 common frames omitted
Caused by: java.lang.ClassNotFoundException: io.micronaut.http.client.HttpClientConfiguration
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        ... 39 common frames omitted

Steps To Reproduce

Create a new micronaut application with discovery-client feature. Run the application.

mn create-app foo.bar --features=discovery-client --build=maven --lang=java

cd bar

mvn mn:run

Environment Information

OS: Windows 11 / WSL 2 (Ubuntu)

$ java -version
openjdk version "17.0.8.1" 2023-08-24
OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.8.1+1 (build 17.0.8.1+1, mixed mode, sharing)

mvn --version
Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)
Maven home: /home/user/.sdkman/candidates/maven/current
Java version: 17.0.8.1, vendor: Eclipse Adoptium, runtime: /home/user/.sdkman/candidates/java/17.0.8.1-tem
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.90.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"

mn --version
Micronaut Version: 4.1.1

Example Application

No response

Version

4.1.1

sdelamo commented 1 year ago

I have verified this happens only in maven. It does not reproduce in a Gradle build.

Replace:

    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-http-client</artifactId>
      <scope>test</scope>
    </dependency> 

with:

    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-http-client</artifactId>
      <scope>compile</scope>
    </dependency>

in your pom.xml

tired-old-man commented 1 year ago

Thanks, nice catch, reading solution it becomes quite obvious that problems is in scope.