I have my Spring-Boot server working well using the 'starter-parent' pom. The problem is that I'd rather not use the spring pom as the parent if at all possible. When I just include the spring-boot-dependencies pom though (as described here), I end up with the driver not being loaded:
18:14:26.127 [localhost-startStop-1] WARN o.a.t.jdbc.pool.PooledConnection - Not loading a JDBC driver as driverClassName property is null.
18:14:26.147 [localhost-startStop-1] ERROR o.a.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/mydb
at java.sql.DriverManager.getConnection(DriverManager.java:689) ~[na:1.8.0_45]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[na:1.8.0_45]
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:305) ~[tomcat-jdbc-8.0.23.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:200) ~[tomcat-jdbc-8.0.23.jar:na]
...
I'm pretty sure this has to do with the driver not being loaded by the DriverManager & ServiceLoader bits, but I'm not sure how to force that to happen. Any suggestions will be much appreciated.
FWIW: If I try to 'Class.forName()' the MySQL jdbc driver I actually end up with a 'NoClassDefFoundError', which is puzzling because the mysql-connector is definitely in my pom. Multiple class loaders or something?
I believe that my issue is related to how maven is importing vs. inheriting dependencies, those provided by my company's parent pom and those coming with spring-boot. I can't really explain it, but if I comment out the dependency management section of our parent pom everything seems to work correctly. This is definitely some kind of mystical maven behavior, but for now I'm working on separating the dependency management and plugin configuration aspects of our parent pom. That way I can inherit the plugin config, and not the dependency management.
Thanks for your help :)
Related
This is a Maven project with Hibernate Search. The Servlet works perfectly on Wildfly 9.
As soon as I start it on Wildfly 10, I get a crash when Spring autowires the beans:
ERROR [ContextLoader]:351 - Context initialization failed
nested exception is java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not a subtype
[...]
Caused by: java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:341)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:247)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1915)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
I tried different version of the declared libraries without success.
<spring.version>4.2.6.RELEASE</spring.version>
<spring.boot.version>1.3.5.RELEASE</spring.boot.version>
<lucene.version>4.10.4</lucene.version>
<hibernate-search-orm.version>5.3.0.Final</hibernate-search-orm.version>
<solr-core.version>4.10.4</solr-core.version>
Anyone have any idea of what's going on?
Both Hibernate ORM and Hibernate Search are included in WildFly since version 8.
A notable difference in WildFly 10 compared to WildFly 9 is that Hibernate Search will be automatically added to your classpath if its usage is being detected. This will make your WAR files smaller and use the latest stable versions so it's the approach I'd recommend (although I'm not a Spring user - would love to hear if it makes things harder for Spring users, please let me know on the Hibernate forums.)
The detection rule is triggered if both:
You are using Hibernate as your persistence provider implementation
Any of your entities are annotated with #Indexed
So I suspect your best solution is to make sure that you're not including neither Hibernate ORM nor Hibernate Search in your deployment to avoid conflicts.
If you rather prefer to use your own version of the frameworks you can set the following property to either not inject these dependencies (so to use the libraries that you bundle in your application), or you can also choose to package custom versions of these in WildFly modules and use the alternative version (you can have alternative versions with a different "slot" identifier).
wildfly.jpa.hibernate.search.module = none
This property needs to be defined in your persistence.xml.
See also the WildFly 10 JPA Reference Guide for a full description of this and similar properties.
I am using Resin 3.1.9 to run Java Web Application with JPA 2.1.
I have put libraries (JAR) on my WEB-INF/lib folder, and I have include them to resin.conf by this:
<class-loader>
<tree-loader path="${resin.root}/webapps/myapp/WEB-INF/lib"/>
</class-loader>
If I didn't include it in resin.conf, I saw an exception about failed to load some classes (even when in first loading on home page).
OK now when loading home page it is no problem, but I wonder when I try to add some record (via CRUD form), it said:
java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider
In fact, class javax.persistence.spi.PersistenceProvider is absolutely exist in "WEB-INF/lib" which is in file "hibernate-jpa-2.1-api-1.0.0.Final.jar"
Is there any debugging step how to check loaded libraries during Resin startup?
Or is there something wrong in my resin.conf?
EDIT
After some investigations, it seems my suggestion of an SPI problem is wrong: double JPA implementations not properly declared raise a PersistenceException.
This is probably not a class loading problem but rather an SPI problem. Have you checked the provider element for hibernate in your persistence.xml ? This should be something like this :
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
Perhaps you should also mention an SPI declaration, but you should only do so if you have multiple implementations available. This is probably the case because of the JPA implementation of your Java EE web profile server.
In such a case, you should add a services folder in your META-INF folder and create a javax.persistence.spi.PersistenceProvider text file inside.
This file should list the two persistence provider implementations (hibernate and the one included in Resin, I don't find it in the documentation).
I am trying to get an apache camel app using CXF working on WebSphere.
Noticed a number of errors
Caused by: java.lang.IncompatibleClassChangeError: org.apache.neethi.AssertionBuilderFactory
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:262)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
This occurs because the org.apache.neethi classes are loaded from the WAS run-time instead of the neeti3.0.2.jar from WEB-INF/lib
here is the info from class loader:
class load: org.apache.neethi.builders.AssertionBuilder from: file:/D:/Tools/WebSphere/AppServer/plugins/org.apache.axis2.jar
The Web Application config has been changed to use the class loader policy. It is set to Parent Last. Yet this class seems to be using the Parent First Policy.
Is there anything in the CXF package that over-rides this policy?
I noticed that using Axis2 and WAS
http://axis.apache.org/axis2/java/core/docs/app_server.html
Avoiding conflicts with WebSphere's JAX-WS runtime has some additional steps mentioned for Axis2. Is there something similar that is required to get this to work?
Thanks
Manglu
Not specific to Camel, but we are dealing with a similar issue.
1) You can use an isolated shared library if you want. This seems to fix the classloader from pulling in these other libraries via OSGi. This solution isn't for everyone.
2) When setting an app that PARENT_LAST, make sure you're doing it in the correct place. If you have jars inside your wars, then you'll have to set PARENT_LAST on the WAR modules, not the application. In the WAS console> Applications > Application Type > websphere enterprise applications> MyEAR > manage Modules > MyWar > Change the "Class loader order" and make it "parent last"
3) After you make your changes, you can export the ear file. In the ear, there is a file META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp/deployment.xml that has this config. For maven ear's, you can put this into src/main/application for it to be packaged up with the ear.
Hope that this helps. Good luck.
We are discussing a similar topic at the Camel mailing lists. I suggest to take a look there: http://camel.465427.n5.nabble.com/camel-cxf-in-WebSphere-without-geronimo-jetty-depdendencies-possible-tp5726490.html
I wanted to implement an EJB client for JBoss 7.1 following this tutorial
http://middlewaremagic.com/jboss/?p=1177#comments which is based on the JBoss tutorial:
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
I already tried the troubleshooting tips there, but still I get an exception:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
Did anyone else encounter this type of problem and knows which jars (or better Maven dependencies) are needed on the classpath?
Best regards,
Helge
Have you referred to the ejb-remote quick start ? https://github.com/jboss-jdf/jboss-as-quickstart/tree/master/ejb-remote
That quick start contains the two Maven projects that are referenced in the jboss.org doc and have all the required dependencies.
I am currently working on a portlet that is using the commons-collections jar file and am getting a NoSuchMethodError. To resolve this issue I need to change the classloader of my WAR file from PARENT_FIRST to PARENT_LAST (in the application.xml file).
However, when I do this my portlet will not launch and when I log into the console it displays the message "The portlet is temporarily disabled". If I change the classloader back to PARENT_FIRST then it will launch again but then I get the NoSuchMethodError.
Does anybody have any suggestions on how to fix this issue ?
I am not sure how, but today I started getting error messages in the logs when I was getting "The portlet is temporarily disabled". I was getting a java.lang.LinkageError which was down to the fact that I had the servlet-api-2.5.jar and a jaxb jar which was conflicting with webshpere j2ee.jar. Once I removed these dependencies and set the classloader to PARENT_LAST, it seems to work properly. It seems that a lot of people face similar issues. The link below is also useful http://forum.springsource.org/showthread.php?33663-dispatcher-servlet-quot-not-a-servlet-class-quot-in-websphere
#MTH,
please try adding commons-collections as a shared library. See here for an example on how others have used shared library support [1]. That will give you the steps, just do it for the jars that you need to override/replace from WAS's classloader
[1] http://portals.apache.org/jetspeed-2/deployguide/deploying-jetspeed-to-websphere.html#section_4_2
thanks,
dims
You haven't provided any logs... but still, one of the most important things to look out for when setting your application to run PARENT_LAST is that your application isn't bundled with any system-level classes that may conflict with the ones provided by WebSphere Portal. For example, classes that pertain to the Portlet specification or the JavaEE specification.