Different image behavior in Google Container Registry vs locally (packaged Spring Boot app) - spring-boot

We have a Spring Boot application (multiple micro-services), packaged with Google Container Builder and published to the registry. Our cloudbuild.yaml looks like this:
steps:
- name: 'gcr.io/cloud-builders/java/gradle'
id: 'java-build'
args: ['build']
- name: 'gcr.io/cloud-builders/docker'
args: ['build',
'-t', 'gcr.io/$PROJECT_ID/api-auth:$COMMIT_SHA',
'-t', 'gcr.io/$PROJECT_ID/api-auth:latest',
'-f', './api-auth/Dockerfile', './api-auth']
waitFor: ['java-build']
- name: 'gcr.io/cloud-builders/docker'
args: ['build',
'-t', 'gcr.io/$PROJECT_ID/api-user:$COMMIT_SHA',
'-t', 'gcr.io/$PROJECT_ID/api-user:latest',
'-f', './api-user/Dockerfile', './api-user']
waitFor: ['java-build']
images:
- 'gcr.io/$PROJECT_ID/api-auth:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/api-auth:latest'
- 'gcr.io/$PROJECT_ID/api-user:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/api-user:latest'
which is called by a trigger on push into the repository on GitHub.
If I run this locally:
container-builder-local --dryrun=false .
resulting images run fine, e.g.:
docker run -e "SPRING_PROFILES_ACTIVE=development" -p 9000:9000 gcr.io/.../api-auth:latest
but when the image is built in the cloud with the Container Builder, the application doesn't work and fails with error that never ocurred before.
Even when pulled:
gcloud docker -- pull gcr.io/.../api-auth:latest
and run locally the new error stops the application from loading:
2017-10-11 16:35:27.661 WARN 5 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in class path resource [org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.authentication.AuthenticationManager]: Factory method 'authenticationManager' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'OAuth2Config': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'authenticationManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
2017-10-11 16:35:27.663 INFO 5 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-10-11 16:35:27.676 INFO 5 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-10-11 16:35:27.718 INFO 5 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-10-11 16:35:27.730 ERROR 5 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
webSecurityConfig (field private org.springframework.security.authentication.AuthenticationManager com.project.auth.config.WebSecurityConfig.authenticationManager)
┌─────┐
| authenticationManager defined in class path resource [org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.class]
↑ ↓
| OAuth2Config (field private org.springframework.security.authentication.AuthenticationManager com.project.auth.config.OAuth2Config.authenticationManager)
└─────┘
This only happens when the image goes through the Cloud Container Builder - neither the local one, nor with a local gradle build.
Could this possibly be a problem in the cloud, or am I missing something trivial?
I have also filed an issue on GitHub, but since it's a broader problem along with the Spring Boot nature of the application, I thought I'd ask here to see if it rings any bell.

Related

Driver claims to not accept jdbcUrl, ${JDBC_DATABASE_URL} when setting externalized config

I'm using the instructions in this Heroku article to attempt to externalize database strings for a hosted Postgres DB. When I use the literal string, I can connect with no issues. However, when I attempt to use the externalized variable ${JDBC_DATABASE_URL}, I'm getting the error message:
2022-06-17 17:30:17.063 WARN 7712 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, ${JDBC_DATABASE_URL}
It looks like it's interpreting the externalized variable itself as a literal string, but I have no idea why. I haven't included any other config files because it is currently working with the database string, but I can attach them if need be. Any ideas?

Using UCANACCESS with Spring Boot

I am setting up a very basic Spring-Boot application, to serve some Access database content as a REST service.
After doing battle with getting the ucanaccess jar included in my classpath, now I'm having trouble getting it to connect to my access db.
My spring.datasource is set like this:
spring.datasource.jdbc-url=jdbc:ucanaccess://C:\\Users\\Owner\\Documents\\brigette.accdb;showSchema=true;memory=false
spring.datasource.dialect=net.ucanaccess.hibernate.dialect.UCanAccessDialect
The error I am getting is:
2020-04-08 09:01:28.534 INFO 20740 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-04-08 09:01:28.557 WARN 20740 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:ucanaccess://C:\Users\Owner\Documents\brigette.accdb;showSchema=true;memory=false
2020-04-08 09:01:28.563 WARN 20740 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [agency/newmeta/jsis/BackendDbConfig.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2020-04-08 09:01:28.568 INFO 20740 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
The access database does exist in that location, but I do get the same error if I use a non-existant db.
HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:ucanaccess://C:\Users\Owner\Documents\lalala.accdb;showSchema=true;memory=false
and also if I use / instead of delimited :
HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:ucanaccess://C:/Users/Owner/Documents/brigette.accdb;showSchema=true;memory=false
What I am missing about setting up the conneciton string?
TIA
Brigette
I suggest you to use another approach: use spring jpa with hibernate.
And follow the article:
Accessing MS Access with Hibernate 5 and Spring Boot
At the end of the day it will guide you to implement a little app to read and update an accdb database.
The important thing to point out is the "patch" included in the source code that must be used in your code (without it , your app will never work).
The "patch" is the hibernate dialect: it is very important, it is reported in the source code of the article and shared at the end of the article.

ActivemQ Artemis with MQTT protocol

[AnnotationConfigEmbeddedWebApplicationContext:559] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedActiveMQ' defined in class path resource [com/els/galaxy/gateway/ArtemisConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolManagerFactory.stripPasswordParameters(Ljava/util/Map;)V
[LocalContainerEntityManagerFactoryBean:597] - Closing JPA EntityManagerFactory for persistence unit 'readPersistenceUnit'
=[LocalContainerEntityManagerFactoryBean:597] - Closing JPA EntityManagerFactory for persistence unit 'writePersistentUnit'
[session:167] - node0 Stopped scavenging
[ContextHandler:1045] - Stopped o.s.b.c.e.j.JettyEmbeddedWebAppContext#7bebe5de{application,/galaxy-gateway,[file:///C:/Users/basireddym/AppData/Local/Temp/jetty-docbase.7636853341168462882.86/],UNAVAILABLE}
[AutoConfigurationReportLoggingInitializer:102] -

Tomcat throws an exception when finishing a Spring Boot application

Sometimes when Tomcat has been running for a while and I terminate the embeded Tomcat (Ctrl+c) the application throws the following exception:
2019-10-17 10:23:10.704 INFO 20020 --- [ Thread-3] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'entityManagerFactory': java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: org/springframework/orm/hibernate5/SpringBeanContainer$SpringContainedBean
Exception in thread "Thread-3" java.lang.NoClassDefFoundError: org/apache/catalina/Lifecycle$SingleUse
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:269)
at org.apache.catalina.startup.Tomcat.stop(Tomcat.java:466)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.stopTomcat(TomcatWebServer.java:254)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.stop(TomcatWebServer.java:309)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.stopAndReleaseWebServer(ServletWebServerApplicationContext.java:305)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onClose(ServletWebServerApplicationContext.java:171)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1032)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:945)
It seems that the exception is thrown when Tomcat has been running for a long time and my application has not been used.
I checked my application jar file and spring-orm-5.1.8.RELEASE.jar is embeded and the class org/springframework/orm/hibernate5/SpringBeanContainer is there.
Any idea is apreciated.
Try to shutdown the application before replacing or renaming the jar.
#see Graceful shutdown fails

"Application Failed to Start"

I am getting the following exception:
2017-05-24 09:41:40.779 INFO 4412 --- [ main] com.develop.NewApplication : Starting NewApplication on DESKTOP-4GP5JJA with PID 4412 (started by Athira S in C:\Users\Athira S\workspace\new)
2017-05-24 09:41:40.779 INFO 4412 --- [ main] com.develop.NewApplication : No active profile set, falling back to default profiles: default
2017-05-24 09:41:40.857 INFO 4412 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#6a28ffa4: startup date [Wed May 24 09:41:40 EDT 2017]; root of context hierarchy
2017-05-24 09:41:41.886 INFO 4412 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-05-24 09:41:42.198 WARN 4412 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2017-05-24 09:41:42.214 INFO 4412 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-24 09:41:42.214 ERROR 4412 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
Assuming you are dealing with a spring boot application, you have 2 solutions:
OPTION 1. If you have a database you can hook up to your application, set the properties group for the spring datasource:
sample application.properties:
spring.datasource.url=jdbc://mysql://localhost:3306/dbname
spring.datasource.username=db_username
spring.datasource.password=db_password
(The same properties group can be set in yml if you are using that:)
sample application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/dbname
username: db_username
password: db_password
OPTION 2. If you don't have a database to connect to
Remove the dependency on spring-boot-starter-jdbc [or spring-boot-starter-jpa as the jdbc starter is a dependency of the starter jpa]
If you are using maven, that dependency looks like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
In gradle, it'd be something like this:
compile 'org.springframework.boot:spring-boot-starter-jdbc'
If this isn't the case for you, please add some more context (such as your pom.xml | build.gradle, and/or application.properties | application.yml so that we can see more of what's going on.
I can not find your question. For this error, you should had some kind of embeded jdbc driver jar, like H2, sqlite, added in your pom. For H2 it is:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
You don't need version, if you use spring-boot-starter-parent as parent.
I was getting this because my port(8080) was being used in the background. killing that PID did the trick for me

Resources