Unable to get available provider resolvers - java

When we use Bean Validation, it is working fine. But after running for some time, there is a RuntimeException:
javax.validation.ValidationException: Unable to get available provider resolvers.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:265)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
at org.dacell.app.order.isale.service.IsaleTradeValidate.validate(IsaleTradeValidate.java:40)
at org.dacell.app.order.isale.service.IsaleTradeValidate$$FastClassByCGLIB$$15097933.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at org.dacell.aspect.ValidateLogAspect.around(ValidateLogAspect.java:49)
at sun.reflect.GeneratedMethodAccessor1869.invoke(Unknown Source)
lib : hibernate-validator-5.0.1.Final.jar

I got this error from WebSphere. validation-api-1.0.0.GA.jar has always been added to the target EAR file. This was never a problem until I changed the class loading strategy to "parent last". I also get this exception:
java.lang.ClassCastException: org.apache.bval.jsr303.ApacheValidationProvider incompatible with javax.validation.spi.ValidationProvider
The solution was to remove validation-api-1.0.0.GA.jar from the target EAR file by adding the following dependency, which sets validation-api to "provided":
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>

Related

No implementation defined for org.apache.commons.logging.LogFactory - Eclipse

I know that there are other questions in stackoverflow talking about similar issue but here the problem is different. I am working on a spring boot project to create a service. The service exposes some APIs, also it retrieves data from another SOAP based service. I added following code to my main method
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
and the application is working just fine when I run it from eclipse and access exposed APIs. However, when I access APIs by executing FatJAR created using maven then I get following error
ERROR [http-nio-8090-exec-7] org.apache.juli.logging.DirectJDKLog: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;] with root cause
java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;
at org.apache.commons.logging.impl.LogFactoryImpl.getClassLoader(LogFactoryImpl.java:447)
at org.apache.commons.logging.impl.LogFactoryImpl.initDiagnostics(LogFactoryImpl.java:476)
at org.apache.commons.logging.impl.LogFactoryImpl.<init>(LogFactoryImpl.java:95)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:153)
If I remove the following line from my main method and create FatJAR
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
and start the service from fatJAR and access APIs then it runs fine. But running application form eclipse and accessing APIs gives the following error
ERROR[0;39m [[34mhttp-nio-8090-exec-4[0;39m] [33morg.apache.juli.logging.DirectJDKLog[0;39m: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory
at org.apache.commons.discovery.tools.DiscoverClass.find(DiscoverClass.java:404)
at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:378)
at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:45)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)
following is the snippet from my POM.
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
The project builds, install, deploy without any issue. The error occurs only when I access the API after running the application. I search other resources they all are saying that there might be some Logging JAR conflict so I removed some dependency and added different dependencies but all the time it ends up in error either in eclipse or FatJAR.
Any help or reference for other resources are welcome.

Spring Boot JSP

Is there any simple way to generate Spring Boot Mvc project for .jsp views?
I've tried to create project in similar way like Spring Boot Rest project, but it's not soo easy for me. I've tried to use official Spring Boot Mvc jsp sample, but when I try to run this I get exception like this:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [sample.jsp.SampleWebJspApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.context.web.SpringBootServletInitializer
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:187) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:765) [spring-boot-1.4.0.BUILD-20160427.203128-289.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.4.0.BUILD-20160427.203128-289.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.4.0.BUILD-20160427.203128-289.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1182) [spring-boot-1.4.0.BUILD-20160427.203128-289.jar:1.4.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1171) [spring-boot-1.4.0.BUILD-20160427.203128-289.jar:1.4.0.BUILD-SNAPSHOT]
at sample.jsp.SampleWebJspApplication.main(SampleWebJspApplication.java:33) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) [idea_rt.jar:na]
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.context.web.SpringBootServletInitializer
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:300) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:237) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:204) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) ~[spring-context-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
... 17 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_65]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_65]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_65]
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) ~[spring-core-4.3.0.BUILD-20160427.201731-353.jar:4.3.0.BUILD-SNAPSHOT]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_65]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_65]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
... 25 common frames omitted
This blog post explains what steps you should take and why. Its fairly easy and I've fixed it myself.
TD:LR
Add Maven Dependencies
In order to enable JSP support, we need to add a few dependencies to our new project in pom.xml.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Place the JSP templates under src/main/resources/META-INF/resources/WEB-INF/jsp/
As I know, the spring boot default page technology is thymeleaf and the official recommends us to use it.
If you want to use jsp, you could do some configuration.
The following steps may be useful.
1. Creating src/main/webapp/WEB-INF/jsp folder.
2. Modify application.properties file.
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
3.Add jar support for jsp. You could add the followings maven repository to your project pom.xml file.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Hope it helps. Any concerns, please feel free to let me know.
Add below dependencies to your POM file:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Create below structure
/src/main/resources/META-INF/resources
Now the above folder is equivalent to your WebContent folder. Inside this you can put your static contents. Add WEB-INF folder here and now you can place your JSP files like any other web project.
In your application.properties file add below:
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
Any chance you're running in IntelliJ? I've noticed this issue as well and the solution is to remove the <scope>provided</scope> from the spring-boot-starter-tomcat dependency, like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
There's a bug in IntelliJ, causing it not to add provided dependencies to the classpath when running locally.
EDIT: Removing the provided scope might cause issues when you're going to run it within a servlet container, so be cautious about that, an explanation about how to fix that could be found in Run Spring-boot's main using IDE.
I have had similar problems, see the link to github.
jsf-spring-boot-2.1.6 parent use spring boot 1.4.0
everything has worked and there is no problems, believe it or not!
https://github.com/joinfaces/joinfaces-example-war
Adding dependency in POM file below
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
Full code avaliable on github link click here
Download the code and import the eclipse/STS using exiting maven project
Next to run the project.
Go to the package on com.chandrakumar.test.demo.
it has "DemoApplication.java" and right click the mouse and select run as
choose the java application.
The browser address bar type "http://localhost:8080/".
Following johnny's reply, I actually wasn't aware that JSP files could be ran while deploying the application as a JAR. Though apparently there are some extensions that I haven't heard of... Typically, a JSP application is deployed as a WAR, and all JSP-related files are located in the webapp/WEB-INF/ folder. You may need to add <packaging>war</packaging> to your POM if if you are comfortable packaging your application as a WAR. This doesn't sound like a bad idea if your application is not a microservice or does not utilize cloud-based technologies. But the majority of cloud-based technologies (excluding cloud-foundry and maybe some others) only support JAR packaging. In that case, you may want to use alternative templates such as Thymeleaf or FreeMarker, over JSP, if you decide to go the JAR route.
Use a maven run configuration with spring-boot:run as the "Command line" value.

Getting java.lang.ClassNotFoundException:MalformedPatternException

While trying to marshal the java object to xml i am getting below exception .
java.lang.ClassNotFoundException: org.apache.oro.text.regex.MalformedPatternException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.castor.xml.AbstractInternalContext.getRegExpEvaluator(AbstractInternalContext.java:325)
at org.exolab.castor.xml.validators.PatternValidator.initEvaluator(PatternValidator.java:262)
at org.exolab.castor.xml.validators.PatternValidator.validate(PatternValidator.java:200)
at org.exolab.castor.xml.validators.StringValidator.validate(StringValidator.java:302)
at org.exolab.castor.xml.validators.StringValidator.validate(StringValidator.java:340)
at org.exolab.castor.xml.FieldValidator.validateInstance(FieldValidator.java:324)
at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:271)
at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1072)
at org.exolab.castor.xml.Validator.validate(Validator.java:135)
at org.exolab.castor.xml.Marshaller.validate(Marshaller.java:2594)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:826)
at in.mywebapp.util.XMLUnmarshaller.getStatusRequestParam(XMLUnmarshaller.java:266)
Not sure which jar is missing .
you are probably missing oro.jar. You can add maven dependency
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
<version>2.0.8</version>
</dependency>
or download the jar from maven repository
Please make sure oro jar file is in classpath. It is not there. So, class loading is failing

javamail using maven and tomcat 6

I am using maven in eclipse and tomcat server.
I have to make small program which sends an email if required every one hour using java mail.
I have modified my web.xml in webapp.
I added mail in POM.xml like this.
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
</exclusions>
</dependency>
as I don't require activation because using the jdk 1.6.
I also modified the context.xml
Then copied the mail.jar into tomcat/lib folder.
But i am getting the weird error.
java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
at fr.project.batch.jobs.SendEmail.execute(SendEmail.java:53)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
2014-04-07 10:01:47,539 ERROR duler_Worker-1 Job (DEFAULT.SendMail threw an exception. [ErrorLogger]
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session]
at org.quartz.core.JobRunShell.run(JobRunShell.java:227)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
at fr.project.batch.jobs.SendEmail.execute(SendEmail.java:53)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
... 1 more
I have read many times in tomcat 6.0 JavaMail ressources and gone through many answers of stackoverflow.
This problem occurs in the server because the lib of Tomcat and you application both have their own copy of mail.jar (in WEB-INF/lib), so the classloaders can load two different Session.If you delete the mail.jarfrom your application, this problem will be solved.

java.lang.ClassNotFoundException: org.quartz.DisallowConcurrentExecution

I've developed some code that executes a quartz job.At first the code was outside the tomcat and it executes very well, but when I tried to embed the same code inside a web application I get java.lang.NoClassDefFoundError: org/quartz/DisallowConcurrentExecution.
I'm using quartz 2.1.5 and it's already in the class path.
Here is the stack trace:
Exception in thread "DefaultQuartzScheduler_QuartzSchedulerThread" java.lang.NoClassDefFoundError: org/quartz/DisallowConcurrentExecution
INFO: Illegal access: this web application instance has been stopped already. Could not load org.quartz.DisallowConcurrentExecution. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
at org.quartz.impl.JobDetailImpl.isConcurrentExectionDisallowed(JobDetailImpl.java:390)
java.lang.IllegalStateException
at org.quartz.simpl.RAMJobStore.acquireNextTriggers(RAMJobStore.java:1447)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1273)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
Caused by: java.lang.ClassNotFoundException: org.quartz.DisallowConcurrentExecution
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.quartz.impl.JobDetailImpl.isConcurrentExectionDisallowed(JobDetailImpl.java:390)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.quartz.simpl.RAMJobStore.acquireNextTriggers(RAMJobStore.java:1447)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
make sure you have only 1 quartz-all-.jar in your classpath (maybe you have 2 : 1 in Tomcat lib folder + 1 in your war)
NoClassDefFoundErrors point to a missing JAR or class on the classpath. In this case the problem is likely that in Tomcat you have quartz-<ver>.jar on your classpath when you actually need quartz-all-<ver>.jar.
for them who use maven can use the new version by add
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.1.7</version>
</dependency>
It should be keep the .jar file inside of the project location. Import .jar file from the outside from the location which the project have is the reason for getting this error. also verified that if the project is a maven project, then it should include the maven dependency in the pom.xml to add the dependency to the project
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org</groupId>
<artifactId>quartz_job</artifactId>
<version>2.2.1</version>
</dependency>

Categories