Caused by: org.jboss.modules.ModuleNotFoundException: org.quartz - jboss

I am adding quartz-2.2.1 scheduler to my application and on deploying it on WildFly 12 the below error is thrown.
Caused by: org.jboss.modules.ModuleNotFoundException: org.quartz
at org.jboss.modules.Module.addPaths(Module.java:1221)
at org.jboss.modules.Module.link(Module.java:1577)
at org.jboss.modules.Module.relinkIfNecessary(Module.java:1605)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:296)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:280)
at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:68)
... 8 more
This is for WildFly 12 application server. Earlier my application was on Jboss6 with quartz-1.8.3 and it's working fine. Now I am trying to upgrade the application server.
Below are the pom.xml dependency code and jboss-deployment-structure.xml under WEB-INF.
pom.xml
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<dependencies>
<module name="org.quartz" />
</dependencies>
</deployment>
</jboss-deployment-structure>
I want to know if I am missing something so that I am getting this error.

Related

Caused by: org.jboss.modules.ModuleNotFoundException: io.jsonwebtoken in jboss-deployment-structure.xml

I am trying to add explicit dependencies to a deployment using
the jboss-deployment-structure.xml file in my maven module.
But I am not getting the io.jsonwebtoken dependency at runtime.
My pom.xml entries
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<scope>provided</scope>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<scope>provided</scope>
<version>13.0.2.Final</version>
</dependency>
My jboss-deployment-structure.xml entries
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.infinispan" export="true"/>
<module name="io.jsonwebtoken" optional="false"/>
<module name="com.fasterxml.jackson.core.jackson-databind" export="true"/>
<module name="org.keycloak.keycloak-core" export="true"/>
<module name="org.keycloak.keycloak-server-spi" export="true"/>
<module name="org.keycloak.keycloak-server-spi-private" export="true"/>
<module name="org.keycloak.keycloak-services" export="true"/>
<module name="org.keycloak.keycloak-saml-core-public" export="true"/>
<module name="org.jboss.logging" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
I am getting the following error when I am trying to create a
jar out of my code use that jar in another service.
06:07:21,356 ERROR [org.jboss.as.controller.management-
operation] (Controller Boot
Thread) WFLYCTL0013: Operation ("deploy") failed - address:
([("deployment" =>
"keycloak-event-listener-1.0.0-SNAPSHOT.jar")]) - failure
description: {"WFLYCTL0080:
Failed services" =>
{"jboss.module.service.\"deployment.keycloak-event-listener-
1.0.0-SNAPSHOT.jar\".main" => "WFLYSRV0179: Failed to load
module:
deployment.keycloak-event-listener-1.0.0-SNAPSHOT.jar
Caused by: org.jboss.modules.ModuleNotFoundException:
io.jsonwebtoken"}}
I tried manifest file also but got the same error only for
io.jsonwebtoken dependency.
Your project is referencing "deployment.keycloak-event-listener-1.0.0-SNAPSHOT.jar" module on Wildfly application server and in turn this same module depends on the "io.jsonwebtoken" module which its not available on Wildfly application server or is not being referenced in the "module.xml" file.
If you need more help just let me know.

Issue in running a dynamic web project tomcat "Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package"

I am trying to migrate an old Web project ( jsp /java) on eclipse. Created a new Dynamic web project. Copied all the code in respective folders and converted the project into a Maven project and added all the required dependencies. Resolved all compiled time errors. When I am running the project on tomcat through eclipse getting following errors.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [18] in the generated java file: [/home/xxx/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/webadmin/org/apache/jsp/login_jsp.java]
Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package
Apr 19, 2019 2:21:03 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet [jsp] threw exception
java.lang.ClassNotFoundException: org.apache.jsp.login_jsp
Issue looks to be something related to configuration only. Tried removing conflicts from pom files , tried at all different paths of hibernate.cfg. used latest possible version of jars in pom
First few lines of web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>webapp</display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>sessionfilter</filter-name>
<filter-class> com.blossom.action.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionfilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<servlet>
<description></description>
<display-name>album_insert</display-name>
<servlet-name>album_insert</servlet-name>
<servlet-class>com.xxx.action.album_insert</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>album_insert</servlet-name>
<url-pattern>/album_insert</url-pattern>
</servlet-mapping>
poi.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>webadmin</groupId>
<artifactId>webadmin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.2.Final</version>
</dependency>
<dependency>
<groupId>com.servlets</groupId>
<artifactId>cos</artifactId>
<version>05Nov2002</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</project>
Build Path
1. Tomcat 9.0
2. EAR Libary
3. JRE (java 8 oracle)
4. Maven dependencies
5. Web app libraries
The program should run without error
Seems there's a version mismatch here, tomcat 9 but catalina 6.0.53.
Catalina dependency needs to be upgraded, something like
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.19</version>
</dependency>
Looking for catalina 6.0.53 on a maven repository shows a warning
Note: This artifact was moved to:
org.apache.tomcat ยป tomcat-catalina
it was a deployment path issue.
After adding Maven dependencies in Properties->Deployment Assembly -> Add ( Java Build Path Entries) -Maven Dependencies the issue is resolved .

Unable to access AuthenticationManager in Keycloak Authentication SPI

I'm writing a custom authentication SPI for Keycloak.
To authenticate cookie, I want to use AuthenticationManager of keycloak-services. I've added keycloak-services as maven dependency in the project. It doesn't give any compilation error but after deploying the SPI on Keycloak, it's throwing me below exception.
Here is the Exception :
ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default
task-68) Uncaught server error: java.lang.NoClassDefFoundError:
org/keycloak/services/managers/AuthenticationManager
at org.keycloak.examples.authenticator.SecretQuestionAuthenticator.authenticate(SecretQuestionAuthenticator.java:102)
at org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:200)
at org.keycloak.authentication.AuthenticationProcessor.authenticateOnly(AuthenticationProcessor.java:853)
at org.keycloak.authentication.AuthenticationProcessor.authenticate(AuthenticationProcessor.java:722)
at org.keycloak.protocol.AuthorizationEndpointBase.handleBrowserAuthenticationRequest(AuthorizationEndpointBase.java:145)
at org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.buildAuthorizationCodeAuthorizationResponse(AuthorizationEndpoint.java:395)
at org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.build(AuthorizationEndpoint.java:139)
Maven Dependency
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi-private</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
It turns out that the way I was deploying the code was causing the issue. I was deploying the code on Keycloak using
mvn clean install wildfly:deploy
When we deploy the code using the above command, it's not able to load jar file in the keycloak context.
To make it work, we have to deploy the code using module structure as mentioned in the Keycloak SPI.
When we deploy the code using module method, we can add the dependencies in the module.xml file of the newly created module, which can then be used in the code.
I was also facing similiar issues in keycloak 15.0.2.
Solved by following this link :
https://keycloak.discourse.group/t/how-to-get-authenticated-user-inside-realmresourceprovider/13260/2
In case the link isn't accessible, this is the solution:
you must add the jboss-deployment-structure.xml in META-INF of the jar
with the required modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.keycloak.keycloak-core" export="true"/>
<module name="org.keycloak.keycloak-server-spi" export="true"/>
<module name="org.keycloak.keycloak-server-spi-private" export="true"/>
<module name="org.keycloak.keycloak-services" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>

REST webservice - Errors while upgrading from Jersey 1 to Jersey 2 with Spring Jersey Plugin

I'm using Jersey 1.8 currently with Jersey Spring plugins 1.8 using JBoss EAP 6.3 and it's working fine with JDK 1.6. Now while upgrading to JDK 1.8 and JBoss EAP 6.4 the Jersey 1.0 is not supported while binding the response [1] . After which I have upgraded the Jersey and Jersey+Spring version to 2.4.1 [2] however I'm getting the "exception: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;" error while starting of the server. Can someone please let me know how to resolve this issue
or any other possible solution to implement with this JDK 1.8 migration?
Tried checking mvn dependency:tree and removed jsr311-api jar from axis2-transport-local jar but still getting the method not found error [3]
Tried comment out the resources configured in "/jboss-eap-6.4\modules\system\layers\base\javax\ws\rs\api\main\module.xml" [5] and got module not found error during start of the server. Even if this works not sure it's the right approach to do.
[1] Binding Error JDK 1.8 and Jersey 1.8
20:01:12,484 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/tst02].[jersey-serlvet]] (ajp-/10.78.180.83:9109-14) JBWEB000236: Servlet.service() for servlet jersey-serlvet threw exception: java.lang.AbstractMethodError
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findSerializer(AnnotationIntrospector.java:1148) [jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]
at org.codehaus.jackson.map.ser.BasicSerializerFactory.findSerializerFromAnnotation(BasicSerializerFactory.java:366) [jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]
at org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:252) [jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]
at org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:782) [jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]
at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:735) [jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]
[2] Error After upgrading to Jersey and Jersey+Spring version with 2.4.1
06:12:53,208 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/tst01]] (ServerService Thread Pool -- 113) JBWEB000289: Servlet jersey-serlvet threw load() exception: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:272) [jersey-server-2.4.1.jar:]
at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:302) [jersey-container-servlet-core-2.4.1.jar:]
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167) [jersey-container-servlet-core-2.4.1.jar:]
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349) [jersey-container-servlet-core-2.4.1.jar:]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-2.jar:1.0.2.Final-redhat-2]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1194) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1100) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3593) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3802) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:163) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:61) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_151]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_151]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_151]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
[4] POM.xml Maven Dependencies for our module
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.4.1</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
[5] JBoss module.xml
-->
<dependencies>
<module name="org.jboss.resteasy.resteasy-jaxrs" services="export"/>
</dependencies>
</module>
Looks to me like you might need to add a jboss-deployment-structure.xml descriptor file (see here for further reading) to exclude the JAX-RS 1.0 dependency added to your classpath by JBoss modules. I had a similar problem which was fixed by adding the following file to the META-INF directory in my EAR:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<sub-deployment name="TheWar.war">
<dependencies>
<module name="javax.jws.api" /> <!-- Required due to exclusion of javaee.api below -->
<module name="javax.servlet.api" /> <!-- Required due to exclusion of javaee.api below -->
<module name="javax.xml.ws.api" /> <!-- Required due to exclusion of javaee.api below -->
</dependencies>
<exclude-subsystems>
<subsystem name="jaxrs" />
<subsystem name="resteasy" />
<subsystem name="webservices" />
</exclude-subsystems>
<exclusions>
<module name="javaee.api" /> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
<module name="javax.ws.rs.api"/> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
<module name="org.jboss.resteasy.resteasy-jaxrs" /> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
<module name="org.jboss.as.jaxrs" /> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
</exclusions>
</sub-deployment>

HTTP 500 - Cannot create JDBC driver of class '' for connect URL 'null'

I have been searching to fix that problem for 3 days reading forums... Then I decided to ask for some help. Nedless to say that your help would be highly appreciated :-)
I created a jndi resource for the mysql connexion in Tomcat context.xml instance in Eclipse
My web app works fine when I start the server from eclipse. It doesn't work fine when I start the web app from eclipse 'Run configurations' with that goals : clean tomcat7:run. My aim is to delegate the build, deploy, start server to maven from eclipse.
I've put the mysql-connector-java-5.1.27.jar in Tomcat_Home/lib.
I don't want to put the datasource configuration in the app (no META-INF....) as one goal of jndi is to place the datasource info out of the app.
Thank you for reading and for the time you'll spend to find a solution.
Technical specifications
eclipse : juno release2
spring tool suite : 3.4
wtp
m2e : 1.4
maven : 3.0.2
jdk : 1.6.21
tomcat : 7.0.25
mysql : 5.6.14
stacktrace
type Exception report
message Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702)
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178)
com.marc.springmvc3.dao.PersonDAO.getPersonById(PersonDAO.java:26)
com.marc.springmvc3.service.PersonService.getAllPersons(PersonService.java:18)
com.marc.springmvc3.mvc.PersonController.getListOfPerson(PersonController.java:33)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123)
org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:723)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702)
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178)
com.marc.springmvc3.dao.PersonDAO.getPersonById(PersonDAO.java:26)
com.marc.springmvc3.service.PersonService.getAllPersons(PersonService.java:18)
com.marc.springmvc3.mvc.PersonController.getListOfPerson(PersonController.java:33)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123)
org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:723)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.NullPointerException
sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
java.sql.DriverManager.getDriver(DriverManager.java:253)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702)
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178)
com.marc.springmvc3.dao.PersonDAO.getPersonById(PersonDAO.java:26)
com.marc.springmvc3.service.PersonService.getAllPersons(PersonService.java:18)
com.marc.springmvc3.mvc.PersonController.getListOfPerson(PersonController.java:33)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123)
org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:723)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.marc</groupId>
<artifactId>spring-mvc-3</artifactId>
<name>spring-mvc-3</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.2.0.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.1</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>runtime</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- JSR 303 with Hibernate Validator -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
</dependency>
<!-- MYSQL driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
<!-- JDBC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<finalName>spring-mvc-3</finalName>
<plugins>
<!-- Maven Tomcat Plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>TomcatServer</server>
<path>/${project.build.finalName}</path>
<port>8080</port>
<charset>UTF-8</charset>
<finalName>${project.build.finalName}</finalName>
<username>ssss</username>
<password>dddddddddd</password>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
</dependencies>
</plugin>
<!-- Maven compiler plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
Servers/tomcat-config/tomcat-users.xml (in Eclipse)
<role rolename="admin"/>
<user username="ssss" password="dddddddddd" roles="admin"/>
web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- database jndi reference -->
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
mvc-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">
<jee:jndi-lookup id="dataSource"
jndi-name="jdbc/TestDB"
expected-type="javax.sql.DataSource"
resource-ref="true"/>
<bean id="personDao" class="com.marc.springmvc3.dao.PersonDAO">
<property name="dataSource" ref="dataSource"/>
</bean>
tomcat context.xml (in eclipse)
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Resource name="jdbc/TestDB"
username="xxx"
password="xxxxxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mytest"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
initialSize="1"/>
<!-- <ResourceLink name="jdbc/TestDB"
global="jdbc/TestDB"
type="javax.sql.DataSource"/> -->
</Context>
I think your tomcat installation is not using your context.xml. Please create fresh tomcat, configure context.xml and libs and run Tomcat directly from system (without Eclipse etc).
Question was updated, answer below is obsolete :/
The important part is:
Cannot create JDBC driver of class '' for connect URL 'null'
Your driver class is null and connection URL is null.
Application configuration requires configured resource jdbc/TestDB on server:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and
<jee:jndi-lookup id="dataSource"
jndi-name="jdbc/TestDB"
expected-type="javax.sql.DataSource"
resource-ref="true"/>
But your Tomcat configuration Servers/tomcat-config/context.xml is wrong. It looks like spring application configuration.
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
...
Standard Tomcat context.xml looks like this:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
username="user" password="pass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testDB?characterEncoding=utf8" maxActive="8"/>
</Context>
I've eventually found out the solution and I'll share it with those who are encountering the same problem.
Create the META-INF folder under src/main/webapp as WEB-INF sibling
Move the Tomcat-config/context.xml file to the META-INF folder. You'll see in the pom.xml that this file is not going to be part of the WAR file.
META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/TestDB"
username="xxxx"
password="xxxxxxxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/TestDB"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
initialSize="1"/>
</Context>
Adapt the pom.xml
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>TomcatServer</server> <!-- user + password defined in the Maven/conf/settings.xml-->
<path>/${project.build.finalName}</path>
<port>8080</port>
<charset>UTF-8</charset>
<finalName>${project.build.finalName}</finalName>
<contextFile>${project.basedir}/src/main/webapp/META-INF/context.xml</contextFile> <!--The path of the Tomcat context XML file. This is not used for war deployment mode.-->
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <!-- driver mysql -->
<version>5.1.27</version>
</dependency>
</dependencies>
</plugin>
MAVEN_HOME/conf/settings.xml
The id is referenced in the pom.xml. The username and the password are declared in the tomcat-users.xml
<server>
<id>TomcatServer</id>
<username>xxxxx</username>
<password>xxxxxxxxx</password>
</server>
Eclipse / Run - Run configurations ...
create new launch configuration
Base direrctory ${workspace_loc:/your project name}
Goals clean tomcat7:run
Apply
Run
Next time you can click on the arrow near the Run As... button in the ToolBar and select the configuration you want to run. The Stop and Relaunch buttons are very useful.
I am using Eclipse STS 3.9.3, tomcat 8.5 and Spring Boot 2.0.0.RELEASE
I spent my entire morning about this problem.
So, I did a lot of things to solve:
Remove jdbc dependence from my pom.
<!-- dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency-->
Declaration resource TOMCAT_HOME/CONF/server.xml whit factory:
<GlobalNamingResources>
...
<Resource name="jdbc/postgres_jndi"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://xxx.xxx.xx.xxx:5432/db"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
removeAbandonedOnBorrow="true"
removeAbandonedOnMaintenance="true"
timeBetweenEvictionRunsMillis="10000"
removeAbandonedTimeout="60"
logAbandoned="true"
username="xxx"
password="xxxxxx"
maxTotal="20"
maxIdle="10"
maxWaitMillis="-1"/>
...
</GlobalNamingResources>
I realized that I was using Eclipse STS. The tomcat resource on server.xml only works after I put the resource declaration in server.xml inside of "Tomcat v8.5 Server at localhost-config" folder in my Server project. Did not work on TOMCAT_HOME/conf folder in server.xml file.
Change my application.yml to:
spring:
datasource:
platform: postgres
jndi-name: java:comp/env/jdbc/postgres_jndi
type: javax.sql.DataSource
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: validate
database-platform: org.hibernate.dialect.PostgreSQL9Dialect
database: POSTGRESQL
show-sql: true
#Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
A application.properties will be like:
spring.datasource.platform= postgres
spring.datasource.jndi-name= java:comp/env/jdbc/postgres_jndi
spring.datasource.type= javax.sql.DataSource
spring.datasource.driver-class-name= org.postgresql.Driver
spring.jpa.hibernate.ddl-auto= validate
spring.jpa.hibernatedatabase-platform= org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.database= POSTGRESQL
spring.jpa.show-sql= true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
Define a context.xml file in src/main/webapp/META-INF/context.xml with definition:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myapp">
<ResourceLink global="jdbc/postgres_jndi" name="jdbc/postgres_jni" type="javax.sql.DataSource"/>
</Context>
Put the file postgresql-42.2.2.jar in the TOMCAT_HOME/lib