Tomcat throws an exception when finishing a Spring Boot application - spring-boot

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

Related

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] -

Wildfly throws UnsupportedOperationException (Naming context is read-only) on start

We're setting up a new staging server (running Ubuntu), and are encountering errors when starting WildFly. The main one seens to be
java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context is read-only
which then causes many errors about missing dependencies.
We have set up our (liquibase) database on another server, which we can ssh into internally. We've scoured StackOverflow as well, and attempted to add
set "JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=**true**"
to our standalone.conf, standalone.bat, and standalone.conf.bat (for the sake of having tried everything!). We also saw that this should've been fixed in WildFly 7.1.1, we're running 9 ourselves (to emulate the live server).
We tried manually installing the dependencies but there are so many - and honestly we think that's just not the main issue.
We're also running nginx and Redis, we saw in the server.log (see below) that the error happens after "Started Hibernate Redis cache" but the error itself seems to be specific to WildFly.
A chunk of server.log is below:
2019-04-03 10:52:38,252 INFO [com.company.ejb.util.config.ConfigRetriever] (ServerService Thread Pool -- 56) Successfully found and read the config file at /opt/wildfly/config.yml
2019-04-03 10:52:38,300 INFO [com.company.ejb.entity.cache.RedisRegionFactory] (ServerService Thread Pool -- 56) Started Hibernate Redis cache
2019-04-03 10:52:46,896 INFO [org.jboss.weld.Event] (MSC service thread 1-2) WELD-000411: Observer method [BackedAnnotatedMethod] com.sun.jersey.server.impl.cdi.CDIExtension.processAnnotatedType(#Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using #WithAnnotations or a generic type with bounds.
2019-04-03 10:52:47,041 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."DoThePublish.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."DoThePublish.ear".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context is read-only
at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:151)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:417)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.createSubcontext(InitialContext.java:298)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:425)
[...]
2019-04-03 10:52:47,078 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "DoThePublish.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"DoThePublish. ear\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"DoThePublish.ear\".WeldStartService: Failed to
start service
Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context is read-only
at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:151)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:417)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.createSubcontext(InitialContext.java:298)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:425)
[...]
"}}
2019-04-03 10:52:47,178 INFO [org.jboss.as.server] (ServerService Thread Pool -- 32) WFLYSRV0010: Deployed "DoThePublish.ear" (runtime-name : "DoThePublish.ear")
2019-04-03 10:52:47,186 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.deployment.unit."DoThePublish.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."DoThePublish.ear".WeldStartService: Failed to start service
2019-04-03 10:52:47,581 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
2019-04-03 10:52:47,582 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
2019-04-03 10:52:47,582 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 9.0.1.Final (WildFly Core 1.0.1.Final) started (with errors) in 42472ms - Started 4599 of 5108 services (362 services failed or missing dependencies, 209 services are lazy, passive or on-demand)
Then following that there's a bunch of missing dependencies (there's looaaaads of these):
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".component.AbstractEntityMainSB.CREATE (missing) dependents: [service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".component.AbstractEntityMainSB.START]
service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".component.AbstractEntityMainSB.START (missing) dependents: [service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".moduleDeploymentRuntimeInformationStart, service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".deploymentCompleteService]
service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".component.AbstractEntityMainSB.VIEW."com.company.ejb.session.AbstractEntityMainSBL".LOCAL (missing) dependents: [service jboss.deployment.subunit."DoThePublish.ear"."CoreEjb.jar".component.AbstractEntityMainSB.START]
We've tried comparing the setup to the existing production (live) server, but there has been a big turnaround in the dev team so no-one knows exactly how they're set up. There are no setup instructions so we're trying things as we go along - perhaps the previous server encountered these same issues but we've no idea.
We are wanting to fix this exception to hopefully be able to start wildfly (and thus our website) without issues (or at least move on to the next error...) Any help is greatly appreciated!
So after a bunch of trying, we figured it out. The line we tried to implement needed to be changed a bit:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"
So we removed the 'set' and removed the asterisks and stuff. In our case it was the .conf file that needed the line, I believe for different types of implementations it might be the .bat or .conf.bat - sorry I can't help further with that.
Hope this helps someone else!
I recently got this same error on startup of JBOSS EAP 7.2 and Wildfly 12. In my case, it's an old Hibernate Java application. The mapping of entities in the hibernate.cfg.xml. My problem was that someone put the name attribute in the <session-factory name="">, and that particular application goes up two contexts! On the startup of the second context, I get the error:
java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context is read-only
Removing the name from the session-factory solved the problem.

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

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.

Resteasy JBoss7 spring-3.2.0-M1

I try to run web-service client on jboss7 and I get strange exception
WARN [org.jboss.as.ee] (MSC service thread 1-4) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to exception: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011054: Could not find default constructor for class org.springframework.web.context.request.async.StandardServletAsyncWebRequest
at org.jboss.as.ee.component.ComponentDescription$DefaultComponentConfigurator.configure(ComponentDescription.java:606)
I read more than one compliant but no one resolution

Resources