cloudfoundry / java-buildpack

Cloud Foundry buildpack for running Java applications
Apache License 2.0
439 stars 2.58k forks source link

Buildpack Version and Spring Boot 1.4.0.RELEASE #327

Closed jonathanamartin closed 8 years ago

jonathanamartin commented 8 years ago

Does the version of Spring Boot defined in the app's pom.xml need to match the version found in the Java Buildpack? Or, does the version of Spring Boot (or auto reconfiguration) in the Java Buildpack need to be configured somehow to match what's in the app?

I'm finding that if I use Spring Boot v1.4.0.RELEASE in my app's POM with version v3.6 or below of the Java Buildpack that I get the following exceptions:

Starting Application [push-test-application] ...
stackato[fence]: Prepared Docker container
stackato[cloud_controller_ng]: Updated app 'push-test-application' -- {"console"=>true, "state"=>"STARTED"}
staging: -----> Downloaded app package (18M)
staging: Cloning into '/tmp/buildpacks/java-buildpack'...
staging: Note: checking out '330a74e76e7ae3fab72ecaf447abae0706a7bea3'.
staging:
staging: You are in 'detached HEAD' state. You can look around, make experimental
staging: changes and commit them, and you can discard any commits you make in this
staging: state without impacting any branches by performing another checkout.
staging:
staging: If you want to create a new branch to retain commits you create, you may
staging: do so (now or later) by using -b with the checkout command again. Example:
staging:
staging:   git checkout -b new_branch_name
staging:
staging: -----> Java Buildpack Version: v3.6 | https://github.com/cloudfoundry/java-buildpack#330a74e
staging: -----> Downloading Open Jdk JRE 1.8.0_71 from https://download.run.pivotal.io/openjdk/precise/x86_64/openjdk-1.8.0_71.tar.gz
staging: (25.2s)
staging:        Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre
staging: (1.1s)
staging: -----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/precise/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz
staging: (0.9s)
staging:        Memory Settings: -Xms160M -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=64M -Xss853K -Xmx160M
staging: -----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://java-buildpack.cloudfoundry.org/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar
staging: (1.3s)
staging: -----> Uploading droplet (63M)
stackato[dea_ng]: Uploading droplet
stackato[dea_ng]: Completed uploading droplet
stackato[fence]: Destroyed Docker container
stackato[fence.0]: Created Docker container
stackato[fence.0]: Prepared Docker container
stackato[dea_ng.0]: Launching web process: CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/j
ava $JAVA_OPTS -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar org.springframework.boot.loader.WarLauncher
app[stdout.0]: 2016-09-02 10:08:00,317 233  [main] INFO  c.w.cloud.PushTestApplication - Starting application as a JAR...
app[stderr.0]: Exception in thread "main"
app[stderr.0]: java.lang.reflect.InvocationTargetException
app[stderr.0]:  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
app[stderr.0]:
app[stderr.0]:  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
app[stderr.0]:
app[stderr.0]:  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
app[stderr.0]:  at java.lang.reflect.Method.invoke(Method.java:497)
app[stderr.0]:  at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
app[stderr.0]:
app[stderr.0]:  at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
app[stderr.0]:  at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
app[stderr.0]:
app[stderr.0]:  at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
app[stderr.0]: Caused by: java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.cloudfoundry.reconfiguration.spring.CloudPropertySourceApplicationContextInitializer
app[stderr.0]:  at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:422)
app[stderr.0]:  at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:401)
app[stderr.0]:
app[stderr.0]:  at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
app[stderr.0]:  at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:261)
app[stderr.0]:  at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:237)
app[stderr.0]:  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
app[stderr.0]:  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
app[stderr.0]:
app[stderr.0]:  at com.wellsfargo.cloud.PushTestApplication.main(PushTestApplication.java:17)
app[stderr.0]:  ... 8 more
app[stderr.0]:
app[stderr.0]: Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextInitializer
app[stderr.0]:
app[stderr.0]:  at java.lang.ClassLoader.defineClass1(Native Method)
app[stderr.0]:  at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
app[stderr.0]:  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
app[stderr.0]:  at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
app[stderr.0]:  at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
app[stderr.0]:
app[stderr.0]:  at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
app[stderr.0]:
app[stderr.0]:  at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
app[stderr.0]:
app[stderr.0]:  at java.security.AccessController.doPrivileged(Native Method)
app[stderr.0]:  at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
app[stderr.0]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
app[stderr.0]:
app[stderr.0]:  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
app[stderr.0]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
app[stderr.0]:  at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:89)
app[stderr.0]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
app[stderr.0]:  at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
app[stderr.0]:  at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:414)
app[stderr.0]:  ... 15 more
app[stderr.0]:
app[stderr.0]: Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextInitializer
app[stderr.0]:  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
app[stderr.0]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
app[stderr.0]:
app[stderr.0]:  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
app[stderr.0]:
app[stderr.0]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
app[stderr.0]:  ... 31 more
app[stderr.0]:
stackato[dea_ng.0]: Unable to successfully start instance (failed to accept connections within health check timeout)
stackato[dea_ng.0]: Unable to successfully start instance (failed to accept connections within health check timeout)
stackato[fence.0]: Created Docker container

I attempted to use v3.7 and above but ran into other exceptions that I'll have to dig into further. For example:

Starting Application [push-test-application] ...
stackato[fence]: Prepared Docker container
stackato[cloud_controller_ng]: Updated app 'push-test-application' -- {"console"=>true, "state"=>"STARTED"}
staging: -----> Downloaded app package (18M)
staging: Cloning into '/tmp/buildpacks/java-buildpack'...
staging: Note: checking out '74974a971ac957f7bae29e5fa7c1b1613fa92c6f'.
staging:
staging: You are in 'detached HEAD' state. You can look around, make experimental
staging: changes and commit them, and you can discard any commits you make in this
staging: state without impacting any branches by performing another checkout.
staging:
staging: If you want to create a new branch to retain commits you create, you may
staging: do so (now or later) by using -b with the checkout command again. Example:
staging:
staging:   git checkout -b new_branch_name
staging:
staging: [Buildpack]                      ERROR Compile failed with exception #<RuntimeError: Open JDK Like Memory Calculator error: No version resolvable for '2.0.2_RELEASE' in 1.0.0_RELEASE, 1.1.0_RELEASE, 1.1.1_RELEASE, 2.0.0_RELEASE, 2.0.1_RELEASE>
staging: Open JDK Like Memory Calculator error: No version resolvable for '2.0.2_RELEASE' in 1.0.0_RELEASE, 1.1.0_RELEASE, 1.1.1_RELEASE, 2.0.0_RELEASE, 2.0.1_RELEASE
staging: Staging failed: Buildpack compilation step failed
stackato[fence]: Destroyed Docker container
Error 170004: App staging failed in the buildpack compile phase (400)

I validated that using Spring Boot 1.3.7.RELEASE and below works with v3.6 and below of the Java Buildpack:

stackato[fence.0]: Created Docker container
stackato[fence.0]: Prepared Docker container
stackato[dea_ng.0]: Launching web process: CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/j
ava $JAVA_OPTS -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar org.springframework.boot.loader.WarLauncher
app[stdout.0]: 2016-09-02 10:33:00,836 349  [main] INFO  c.w.cloud.PushTestApplication - Starting application as a JAR...
app[stdout.0]:
app[stdout.0]:   .   ____          _            __ _ _
app[stdout.0]:  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
app[stdout.0]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app[stdout.0]:  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
app[stdout.0]:   '  |____| .__|_| |_|_| |_\__, | / / / /
app[stdout.0]:  =========|_|==============|___/=/_/_/_/
app[stdout.0]:  :: Spring Boot ::        (v1.3.7.RELEASE)
app[stdout.0]:
app[stdout.0]: 2016-09-02 10:33:02,521 2034 [main] INFO  o.c.r.s.CloudPropertySourceApplicationContextInitializer - Adding 'cloud' PropertySource to ApplicationContext
app[stdout.0]: 2016-09-02 10:33:03,075 2588 [main] INFO  o.c.r.s.CloudAutoReconfigurationApplicationContextInitializer - Adding cloud service auto-reconfiguration to ApplicationContext
app[stdout.0]: 2016-09-02 10:33:03,094 2607 [main] INFO  c.w.cloud.PushTestApplication - Starting PushTestApplication on af04e872c9ec with PID 148 (/home/stackato/app/WEB-INF/classes started by stackato in /home/stackato/app)
app[stdout.0]: 2016-09-02 10:33:03,095 2608 [main] INFO  c.w.cloud.PushTestApplication - The following profiles are active: cloud
app[stdout.0]: 2016-09-02 10:33:04,014 3527 [main] INFO  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@337d0578: startup date [Fri Sep 02 10:33:04 EDT 2016]; root of context hierarchy
app[stdout.0]: 2016-09-02 10:33:04,760 4273 [background-preinit] INFO  o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.2.4.Final
app[stdout.0]: 2016-09-02 10:33:06,329 5842 [main] INFO  o.c.r.s.DataSourceCloudServiceBeanFactoryPostProcessor - Auto-reconfiguring beans of type javax.sql.DataSource
app[stdout.0]: 2016-09-02 10:33:06,331 5844 [main] INFO  o.c.r.s.DataSourceCloudServiceBeanFactoryPostProcessor - No beans of type javax.sql.DataSource found. Skipping auto-reconfiguration.
app[stdout.0]: 2016-09-02 10:33:07,495 7008 [main] INFO  o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 55257 (http)
app[stdout.0]: 2016-09-02 10:33:09,849 9362 [main] INFO  o.a.catalina.core.StandardService - Starting service Tomcat
app[stdout.0]: 2016-09-02 10:33:09,900 9413 [main] INFO  o.a.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/8.0.36
app[stdout.0]: 2016-09-02 10:33:10,313 9826 [localhost-startStop-1] INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
app[stdout.0]: 2016-09-02 10:33:10,313 9826 [localhost-startStop-1] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 6305 ms
app[stdout.0]: 2016-09-02 10:33:10,913 10426 [localhost-startStop-1] INFO  o.s.b.c.e.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
app[stdout.0]: 2016-09-02 10:33:10,920 10433 [localhost-startStop-1] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
app[stdout.0]: 2016-09-02 10:33:10,921 10434 [localhost-startStop-1] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
app[stdout.0]: 2016-09-02 10:33:10,921 10434 [localhost-startStop-1] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
app[stdout.0]: 2016-09-02 10:33:10,921 10434 [localhost-startStop-1] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
app[stdout.0]: 2016-09-02 10:33:11,588 11101 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@337d0578: startup date [Fri Sep 02 10:33:04 EDT 2016]; root of context hierarchy
app[stdout.0]: 2016-09-02 10:33:11,750 11263 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/]}" onto public java.lang.String com.wellsfargo.cloud.HomeController.showHome(org.springframework.ui.Model)
app[stdout.0]: 2016-09-02 10:33:11,753 11266 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
app[stdout.0]: 2016-09-02 10:33:11,753 11266 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
app[stdout.0]: 2016-09-02 10:33:11,802 11315 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
app[stdout.0]: 2016-09-02 10:33:11,803 11316 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
app[stdout.0]: 2016-09-02 10:33:11,869 11382 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
app[stdout.0]: 2016-09-02 10:33:12,757 12270 [main] INFO  o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
app[stdout.0]: 2016-09-02 10:33:12,818 12331 [main] INFO  o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-55257"]
app[stdout.0]: 2016-09-02 10:33:12,829 12342 [main] INFO  o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-55257"]
app[stdout.0]: 2016-09-02 10:33:12,860 12373 [main] INFO  o.a.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
app[stdout.0]: 2016-09-02 10:33:12,890 12403 [main] INFO  o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat started on port(s): 55257 (http)
stackato[dea_ng.0]: Instance is ready
app[stdout.0]: 2016-09-02 10:33:12,921 12434 [main] INFO  c.w.cloud.PushTestApplication - Started PushTestApplication in 11.858 seconds (JVM running for 12.791)
OK

Note, I'm using the HPE Stackato CF implementation which adds another variable.

nebhale commented 8 years ago

No, the version of Spring Boot does not need to match what is referenced in the buildpack. The version you see there is for the Spring Boot CLI which is not used to run self-executable JARs and WARs. However, v3.6.1 was released on January 29, 2016 nearly 8 months before Spring Boot 1.4 and therefore doesn't know how to run it. If my memory serves me, Spring Boot 1.4 support was added in v3.7 released on April 20, 2016. You should use one of the four versions of the buildpack released in the last four months with Spring Boot 1.4.

jonathanamartin commented 8 years ago

Makes sense and much appreciated.

nebhale commented 8 years ago

The error you're seeing with v3.7 is because the repository your buildpack is referencing does not appear to be up to date either. The canonical version of the repository contains the requested 2.0.2_RELEASE version.

jonathanamartin commented 8 years ago

Hey thanks that helps. I've got a local micro cloud installed. It's got about 22 patches outstanding. I probably just need to run through those.

Edit 1 Just thought more about your statement. If it's a URL defined in the v3.7 Java Buildpack then cluster patches probably wouldn't do much. Are you saying the repository URL changed and "use the latest Java Buildpack"?

Edit 2 Read this: https://github.com/cloudfoundry/java-buildpack/blob/master/docs/extending-repositories.md I think I've got enough to go on now.