0

I am running a Spring Boot / Spring Cloud application. Here is a snippet of my POM file:

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.5</version>
  </parent>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>2022.0.1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

I have a lot of dependencies in my POM file, but most of them are part of the BOM for the Spring Cloud release.

I am running the micro service locally against the latest Eclipse Temurin Java 20 OpenJDK on my MacOS. When I run my micro service from within Eclipse 2023-06, the Spring Boot application runs fine. When I run it via the command line, it also runs fine.

However, when I run it in a Docker Container built as follows:

FROM eclipse-temurin:20
ARG JAR_FILE
RUN mkdir -p /usr/local/product
RUN echo $JAVA_HOME
RUN echo "using jar file: $JAR_FILE"
ADD target/lib /usr/local/product/lib
ADD target/${JAR_FILE} /usr/local/product/vina-product.jar
ADD docker_files/run.sh run.sh
RUN chmod +x run.sh
CMD ./run.sh

Here is the content of my run.sh file:

#!/bin/sh
java -jar /usr/local/product/vina-product.jar

The micro service throws an exception. Here is the Stack Trace:

02:42:10.774 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vinaProductApplication' defined in BeanDefinition defined in null: Unexpected AOP exception
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:605)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:967)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293)
    at com.mahytech.vina.product.VinaProductApplication.main(VinaProductApplication.java:12
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
 Caused by: org.springframework.aop.framework.AopConfigException: Unexpected AOP exception
    at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:222)
    at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:158)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
    at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:115)
    at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.setBeanFactory(GenericScope.java:448)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1791)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
    ... 18 common frames omitted
 Caused by: java.lang.ClassCastException: class com.mahytech.vina.product.VinaProductApplication$$SpringCGLIB$$0 cannot be cast to class org.springframework.cglib.proxy.Factory (com.mahytech.vina.product.VinaProductApplication$$SpringCGLIB$$0 and org.springframework.cglib.proxy.Factory are in unnamed module of loader 'app')
    at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:91)
    at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:213)
    ... 25 common frames omitted

The only difference between the two environments is that one is run on my MacOS system against the OpenJDK Eclipse Temurin and the Docker Container is built using Eclipse Temurin's Docker image. What could be the cause of this exception?

I have run the Spring Boot / Spring Cloud micro service via Eclipse as well as via my MacOS Command Line, at it works fine. However, when run via the eclipse-temurin:20 Docker Image I receive the exception noted previously.

Craig Mahy
  • 31
  • 2
  • I created the Docker container using "FROM amazoncorretto:20-alpine" and I get the same error. Therefore the issue is not eclipse-temurin. – Craig Mahy Aug 04 '23 at 21:51
  • It also may have to do with Redis. I am using a Redis server in my micro services. I display a log where the Redis Server is being created when running on my MacOS. When running in the container, at that exact place in the logs I get the following: WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vinaProductApplication' defined in BeanDefinition defined in null: Unexpected AOP exception – Craig Mahy Aug 04 '23 at 22:28
  • These micro services were running fine when I was using the HOXTON.RELEASE Spring Cloud version and Spring Boot 2.2.8.RELEASE. I am trying to bring my micro services up to date with as close to the latest Spring Boot and Cloud versions as possible. I know that is never easy! – Craig Mahy Aug 04 '23 at 22:35
  • Another factor that may be contributing to the issue is that I have gone from Java 11 to Java 17. I would not think that moving to Java 17 would cause something like this, but it may have. – Craig Mahy Aug 09 '23 at 15:59

0 Answers0