Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Auto Reconfiguration is not operational when deploying EAR #23

Open
violetagg opened this issue Aug 18, 2017 · 19 comments
Open

Spring Auto Reconfiguration is not operational when deploying EAR #23

violetagg opened this issue Aug 18, 2017 · 19 comments

Comments

@violetagg
Copy link
Member

When Spring Auto Reconfiguration is enabled and there is spring-core*.jar artifacts [1]
in the application binaries, a modification of web.xml provided by web module will be made
and Spring Auto Reconfiguration jar file will be added to the additional libraries [2].

When the deployment artifact is WAR file the collection of the additional libraries will be added
to WEB-INF/lib [3]. Thus Spring Auto Reconfiguration will be able to load classes provided by spring-core*.jar.

In case of EAR the additional libraries will be added to <TomEE-Home>/lib [3]. Thus
Spring Auto Reconfiguration will not be able to load the classes provided by spring-core*.jar
because they are provided by the application binaries and not by TomEE installation.

The exception below will appear:

   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextInitializer
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.defineClass1(Native Method)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.security.AccessController.doPrivileged(Native Method)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:225)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:83)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.cloudfoundry.reconfiguration.spring.AutoReconfigurationServletContainerInitializer.<clinit>(AutoReconfigurationServletContainerInitializer.java:33)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.Class.forName0(Native Method)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.Class.forName(Class.java:348)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:188)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:159)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1622)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.OpenEJBContextConfig.processServletContainerInitializers(OpenEJBContextConfig.java:479)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1135)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.OpenEJBContextConfig.webConfig(OpenEJBContextConfig.java:402)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:775)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.OpenEJBContextConfig.configureStart(OpenEJBContextConfig.java:123)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5087)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	... 23 more
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextInitializer
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   2017-08-10T14:37:48.66-0400 [APP/PROC/WEB/0] OUT 	... 52 more

[1] https://github.com/cloudfoundry-community/tomee-buildpack/blob/master/lib/java_buildpack/framework/spring_auto_reconfiguration.rb#L53
[2] https://github.com/cloudfoundry-community/tomee-buildpack/blob/master/lib/java_buildpack/framework/spring_auto_reconfiguration.rb#L39
[3] https://github.com/cloudfoundry-community/tomee-buildpack/blob/master/lib/java_buildpack/container/tomee/tomee_instance.rb#L62

@violetagg violetagg changed the title Spring Auto Reconfiguration is not operational when the deploying EAR Spring Auto Reconfiguration is not operational when deploying EAR Aug 18, 2017
@violetagg
Copy link
Member Author

cc @kelapure

@bijukunjummen
Copy link
Contributor

bijukunjummen commented Aug 29, 2017

@kelapure and I are starting to look at this @violetagg - one question though, how did you get this condition to trigger to simulate the scenario for the ear file:

@configuration['enabled'] && (@droplet.root + '**/*spring-core*.jar').glob.any?

@nebhale
Copy link
Contributor

nebhale commented Aug 29, 2017

Any EAR file that contains a WAR using Spring Boot, would do it.

@bijukunjummen
Copy link
Contributor

Thanks @nebhale, however then the war in the ear will have to be in an exploded form right for the jars in there to be visible to the buildpack. I will assume that to be the case and try to simulate the issue that @violetagg is seeing

@nebhale
Copy link
Contributor

nebhale commented Aug 29, 2017

That is correct, and that is how the application we were working with was laid out.

@bijukunjummen
Copy link
Contributor

Do you mind providing a sample @nebhale, @violetagg , a sample that I have with a spring boot war packaged in an ear is not starting up at all - https://github.com/bijukunjummen/ear-with-boot, for me to simulate the issue

//cc @kelapure

@bijukunjummen
Copy link
Contributor

@violetagg, can you please provide your sample which has this issue.

@violetagg
Copy link
Member Author

@bijukunjummen
test-ear.zip

Try with this one. You should be able to see

   2017-09-07T19:12:03.32+0300 [APP/PROC/WEB/0] OUT Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextInitializer
   2017-09-07T19:12:03.32+0300 [APP/PROC/WEB/0] OUT 	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
   2017-09-07T19:12:03.32+0300 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   2017-09-07T19:12:03.32+0300 [APP/PROC/WEB/0] OUT 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   2017-09-07T19:12:03.32+0300 [APP/PROC/WEB/0] OUT 	... 52 more

@bijukunjummen
Copy link
Contributor

Awesome, thanks @violetagg, will give this a try and get back to you

bijukunjummen added a commit to bijukunjummen/ear-with-boot that referenced this issue Sep 9, 2017
@bijukunjummen
Copy link
Contributor

I can see only a couple of potential fixes @violetagg, @nebhale , @kelapure

  1. Disable Spring Auto-reconfiguration altogether for ear files.
  2. Add documentation to show how to disable auto-reconfiguration in case of exploded ear files
  3. Copy auto-reconfiguration jars to ALL exploded wars in an ear file and NOT to tomee-lib.

1 and 2 should be very easy, 3 I feel will be tricky since there are now potentially more than 1 target folder. Let me know what you think and I can attempt a fix along those lines.

@mgvinuesa
Copy link

mgvinuesa commented Feb 15, 2018

Hi,

In the issue you talk about a exploded EAR (with the wars "unzipped") but I have a EAR structure similar to this:

sample.ear
|____drivers
| |____driver.jar
|____war1-1.0.war
|____war2-1.0.war
|____lib
  |____ thirdlibrary1.jar
  |____ thirdlibrary2.jar
  |____...
|____META-INF|
 |____application.xml

My wars aren't exploded.

And to provide all the common libs out of the WARs included spring libs the skinnyWars option is enabled in maven plugin. But I have the same error in my logs.

2018-02-15T16:33:04.808+01:00 [APP/PROC/WEB/0] [OUT] Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextInitializer .... 2018-02-15T16:33:04.808+01:00 [APP/PROC/WEB/0] [OUT] Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextInitializer

The problem is that I would have to put all the libraries inside the WAR due to if I put only the spring libraries the other libraries won't be able to access to spring classes (classpath hierarchy WAR -> EAR -> tomEE)

@mgvinuesa
Copy link

Hi @violetagg
Any news about this issue?

@violetagg
Copy link
Member Author

Hi,

Can you provide a sample application (with war files that are not exploded)?

Thanks,
Violeta

@mgvinuesa
Copy link

mgvinuesa commented Mar 1, 2018

Yes of course

ear-distribution-0.0.1-SNAPSHOT.ear.zip

I use the following manifest

---
applications:
  - name: BACKEND.TEST
    path: ear-distribution-0.0.1-SNAPSHOT.ear
    memory: 1G

   
#buildpack: https://github.com/cloudfoundry-community/tomee-buildpack#4.9
buildpack: https://github.com/cloudfoundry-community/tomee-buildpack#v4.8

env:
    JBP_LOG_LEVEL: INFO
#    JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'

To avoid the error I have to disable the AUTO_RECONFIGURATION, in the other hand if you disable it and run the application to can reproduce the error related with the other issue #32 that I have opened making the following GET request:

https://<host>/backend-ssmm-cloud/contrato/

@violetagg
Copy link
Member Author

@mgvinuesa Thanks for the sample app. It helped a lot.

In your use case Spring Auto Reconfiguration detects that there are spring framework libraries in the EAR/lib folder and because of this it tries to reconfigure the application.

Do you need the Spring Auto Reconfiguration? If not I would recommend to disable it.

Regards,
Violeta

@mgvinuesa
Copy link

@violetagg I supposed, same situation that with exploded ears.

Currently I don't need it but maybe in the future, according with what Spring Auto Reconfiguration consists:

  • it adds the cloud profile to Spring's list of active profiles
  • it exposes all of the properties contributed by Cloud Foundry as a PropertySource in the ApplicationContext
  • it re-writes the bean definitions of various types to connect automatically with services bound to the application.

The second one maybe we would need in the future but I suppose that we could get the information manually.

thanks by your support.

@bijukunjummen
Copy link
Contributor

Should we do point 2 in #23 (comment) @violetagg , @kelapure, I can attempt a PR

@kelapure
Copy link

kelapure commented Mar 5, 2018

@bijukunjummen - can we explore how to fix this issue with 3 in #23. I feel like just documenting this is not good enough.

@violetagg
Copy link
Member Author

Yes I also think that when we have EAR with exploded war files we will be able to provide Spring Auto Reconfiguration.
For EAR where war files are not exploded it will be a bit complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants