Spring Boot 1.4 + Hibernate 5 Integration Test ''java.io.IOException: Too many open files Error'' - spring

I use spring boot 1.4 for testing (the new annotation #SpringBootTest ...)
when i run it integration test.i get the following error:
[2016-10-11 11:54:13.762] [tiger-All-Series] [main] [] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean#buildNativeEntityManagerFactory:382 - Initialized JPA EntityManagerFactory for persistence unit 'default'
[2016-10-11 11:54:13.993] [tiger-All-Series] [pool-6-thread-1] [] ERROR o.a.h.i.n.c.InternalHttpAsyncClient#run:66 - I/O reactor terminated abnormally
org.apache.http.nio.reactor.IOReactorException: Failure opening selector
at org.apache.http.impl.nio.reactor.AbstractIOReactor.<init>(AbstractIOReactor.java:103)
at org.apache.http.impl.nio.reactor.BaseIOReactor.<init>(BaseIOReactor.java:85)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:318)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:192)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Too many open files
at sun.nio.ch.IOUtil.makePipe(Native Method)
at sun.nio.ch.EPollSelectorImpl.<init>(EPollSelectorImpl.java:65)
at sun.nio.ch.EPollSelectorProvider.openSelector(EPollSelectorProvider.java:36)
at java.nio.channels.Selector.open(Selector.java:227)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.<init>(AbstractIOReactor.java:101)
... 5 common frames omitted
this happened on the second test class. (it seems the problem of the Hibernate EntityManagerFactory) ,i get some information form here stackoverflow
but it can`t resolve my problem

Related

How to ignore mongo when start application

A legacy Spring boot project, before it used mongo, but now it does not need. Now start this project it has this error
2022-10-27 14:10:13.119 [cluster-ClusterId{value='635a20bb714f8f71e2e5d041', description='null'}-10.48.51.21:40010] [INFO] [org.mongodb.driver.cluster] - Exception in monitor thread while connecting to server 10.48.51.21:40010
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
then I exclude related Auto Configuration class
#SpringBootApplication(exclude={MongoAutoConfiguration.class, MongoRepositoriesAutoConfiguration.class,MongoDataAutoConfiguration.class})
but this time project start failed
***************************
APPLICATION FAILED TO START
***************************
Description:
Field mongoTemplate in com.bxt.bmht_support.dao.BmhtMideTableDao required a bean of type 'org.springframework.data.mongodb.core.MongoTemplate' that could not be found.
How to disable mongo without update current code? just want ignore it.

Compatibility spring-batch / spring / hibernate

I have evolved versions in my application (for example hibernate 3.2.6.ga >> 5.1.0.Final), and since then I have an error when launching my spring batch job:
Caused by: java.sql.SQLException: You can't operate on a closed Connection!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.c3p0.impl.NewProxyConnection.commit(NewProxyConnection.java:809)
at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:80)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:232)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
... 13 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyConnection.commit(NewProxyConnection.java:803)
... 17 more
Versions are :
hibernate 5.1.0.Final
spring 3.1.0.RELEASE
spring-batch 2.0.0.M3
c3p0 0.9.1.2
Is the problem the spring batch version ?

dropwizard and hive/hiverunner integration with maven

most of the dropwizard:0.9.2 maven dependencies use glassfish jersey 2:
org.glassfish.jersey.media:jersey-media-multipart:jar:2.22.1:compile
org.apache.hive:hive-service:1.2.1 and com.klarna.hiverunner:3.1.0 both use com.sun.jersey 1:
com.sun.jersey:jersey-client:jar:1.9:runtime
I keep getting the following error:
java.lang.RuntimeException: javax.servlet.ServletException: io.dropwizard.jersey.setup.JerseyServletContainer-2acbc859#570b3305==io.dropwizard.jersey.setup.JerseyServletContainer,1,false
Caused by: A MultiException has 3 exceptions. They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
I get the following if I exclude jersey-core from hive:
java.lang.NoSuchMethodError: org.apache.hive.service.server.HiveServer2.init(Lorg/apache/hadoop/hive/conf/HiveConf;)V
The goal is to set up an in-memory hive using hiverunner then write stuff to hiveDB (Derby) using dropwizard API endpoints.
Looks like jersey 2 stopped using jersey 1's JSONJAXBContext.
Is there a proper way to get around this jersey 1 & 2 dependency conflict?

Spring boot - Eclipelink scanning orm.xml

I'm converting an existing application to spring boot, when I run the application using the created jar I get an exception when it scans and finds an orm.xml inside my entities jar (included as a dependency).
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException:
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: org.springframework.boot.loader.LaunchedURLClassLoader#38cdedfd
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [UAccessPersistenceUnit] failed.
Internal Exception: java.lang.RuntimeException: java.io.IOException: Unable to open root Jar file 'jar:file:everything-jar.jar'
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [UAccessPersistenceUnit] failed.
Internal Exception: java.lang.RuntimeException: java.io.IOException: Unable to open root Jar file 'jar:file:everything-jar.jar'
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1954)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1945)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)
... 46 common frames omitted
Caused by: org.eclipse.persistence.exceptions.EntityManagerSetupException:
Exception Description: Predeployment of PersistenceUnit [UAccessPersistenceUnit] failed.
Internal Exception: java.lang.RuntimeException: java.io.IOException: Unable to open root Jar file 'jar:file:everything-jar.jar'
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
... 50 common frames omitted
This isn't using spring data, i'm building the datasources from a external properties file at the moment. It's the scanning that seems to cause issues.
This is spring boot 1.1.5-RELEASE with eclipselink 2.5.1
everything-jar.jar is a spring boot packed jar. With my compiles classes, the spring boot loader and the entities packaged in a jar. I've marked the dependency to be unpacked and it works, but it's not ideal.
This problem keeps coming up, now if I try to load persistence.xml from another jar it throws this same exception.
After a lot of investigation it seems there are two parts to the problem here.
The spring boot loader supports urls that look something like this :
jar:file:!/!/
Eclipselink generates urls for embedded orm.xml files like so
jar:jar:file:!/!/
I've got a fix in spring boot to make it better at opening the eclipselink URLs, but for an immediate fix we need to create a custom ArchiveFactoryImpl and override the createArchive method to return a custom JarInputStreamURLArchive when the protocol is jar.
In this custom class override the get entry as URL to check for a url with a protocol of jar that starts with jar and create a new URL from the file of the original (this cuts off the protocol part from the original url giving us jar:url instead of jar:url:url
public URL getEntryAsURL(String entryPath) throws IOException {
URL entryUrl = super.getEntryAsURL(entryPath);
if(entryUrl == null) {
return null;
}
if("jar".equals(entryUrl.getProtocol()) && entryUrl.getFile().startsWith("jar:")) {
//cut off the jar portions
String file = entryUrl.getFile();
return new URL(file);
} else {
return entryUrl;
}
}

Invalid bundle when starting Apache Karaf

I have a curious behavior when I start my Karaf.
My JAR bundle contains a simple camel spring xml route that transforms an incoming xml fragment to text with an xslt. I use a BridgePropertyPlaceholderConfigurer to externalize my properties into {karaf.base}/etc/karaf-invalid-bundle.cfg.
To illustrate my post, I created a github repository https://github.com/johanlelan/Karaf-invalid-bundle-example.
Occasionally, my bundle fails to start for a strange cause:
karaf#root> log:display-exception
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route error.sample at: >>> To[xslt:xslt/template.xslt] <
<< in route: Route(error.sample)[[From[ref:incoming.endpoint]] -> [SetHea... because of java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1352)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:301)[121:org.apache.camel.camel-spring:2.12.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:96)[78:org.springframework.context:3.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)[78:org.springframework.context:3.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:948)[78:org.springframework.context:3.2.4.RELEASE]
at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:235)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:358)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)[118:org.springframework.osgi.extender:1.2.1]
at java.lang.Thread.run(Thread.java:662)[:1.6.0_45]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route error.sample at: >>> To[xslt:xslt/template.xslt] <<< in route: Route(error.sample)[[From[ref:incoming.endpoint]] -> [SetHea... because of java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:912)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:177)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:770)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1914)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1670)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1544)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:179)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1512)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:228)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:118)[121:org.apache.camel.camel-spring:2.12.2]
... 10 more
Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1352)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.core.osgi.OsgiServiceRegistry.findByTypeWithName(OsgiServiceRegistry.java:110)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.impl.CompositeRegistry.findByTypeWithName(CompositeRegistry.java:87)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.findByTypeWithName(PropertyPlaceholderDelegateRegistry.java:70)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.processor.interceptor.DefaultChannel.getOrCreateBacklogTracer(DefaultChannel.java:339)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.processor.interceptor.DefaultChannel.initChannel(DefaultChannel.java:202)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.wrapChannel(ProcessorDefinition.java:269)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.wrapProcessor(ProcessorDefinition.java:251)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:507)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:213)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:909)[113:org.apache.camel.camel-core:2.12.2]
... 20 more
Caused by: java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514)[org.apache.felix.framework-4.0.3.jar:]
at org.apache.felix.framework.BundleContextImpl.getAllServiceReferences(BundleContextImpl.java:411)[org.apache.felix.framework-4.0.3.jar:]
at org.apache.camel.core.osgi.OsgiServiceRegistry.findByTypeWithName(OsgiServiceRegistry.java:94)[121:org.apache.camel.camel-spring:2.12.2]
... 29 more
karaf#root>
I think that this error is linked to my properties or to my BundleActivator class.
Any ideas on the way to stop this behavior?
Johan
Not sure about your concrete problem in spring. I stopped using spring on OSGi a long time ago.
A much easier solution would be to just use blueprint instead of spring. You can then use the config admin support of blueprint to attach to the config file in etc. BLueprint runs much smoother in OSGi than spring dm.
You also have the advantage that config admin properties configured by blueprint are automatically available as camel properties.

Resources