Spring boot application suddenly fails to start. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" - spring

I m new to spring. I was writing spring boot applications with maven in last few days and had no issue in building or running on windows with STS. Then today for packaging i created a new project and and tried to build it with maven using win command prompt. Build failed and said that theres no compiler set("Perhaps your'e using a JRE"). Then I set JAVA_HOME in system variables and retried but then it started giving me
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
SLF4J: Defaulting to no-operation (NOP) logger implementation
....
Caused by:
java.lang.ClassNotFoundException:ch.qos.logback.classic.turbo.TurboFilter
Now I can't run any app which were working fine earlier either with STS/Eclipse, that error pops up.
I deleted .m2 and rebuilt.still not working.
Tried in a different windows pc with a fresh STS installation. It also doesn't work. this pops up.
Did they change libraries?
I deleted JAVA_HOME and retried.But no success.
I'm using a pretty simple pom and an application.
<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>com.pmanu</groupId>
<artifactId>testMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
AppStart.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#RestController
#SpringBootApplication
public class AppStart {
public static void main(String[] args) {
SpringApplication.run(AppStart.class, args);
}
#RequestMapping("/")
public String get(){
return "Hello";
}
}
Please Help. I'd prefer to go ahead with spring 1.5.6.RELEASE artifacts.
I saw some answers saying that a logging jar like log4j has to be added to classpath.
But isn't maven parent supposed to have them configured? If there's any other proper way I'd prefer not to add an unnecessay dependancy for my applications.
How come this arised all of a sudden?

Related

Starting Quarkus in Dev Mode results in NoSuchMethodError: org.jboss.threads.JBossExecutors.rejectingExecutor()Ljava/util/concurrent/Executor

I am currently migrating a java web application to quarkus. After having migrated all code parts and done most adaptions, I wanted to try it out by running the app in dev mode:
./mvnw compile quarkus:dev
But it crashes right at the beginning with a NoSuchMethodError for java/util/concurrent/Executor:
2022-04-01 18:07:06,022 INFO [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start live reload endpoint to recover from previous Quarkus startup failure
2022-04-01 18:07:07,444 INFO [org.jbo.threads] (main) JBoss Threads version 2.3.3.Final
2022-04-01 18:07:07,451 ERROR [io.qua.dep.dev.DevModeMain] (main) Quarkus dev mode failed to start: java.lang.NoSuchMethodError: org.jboss.threads.JBossExecutors.rejectingExecutor()Ljava/util/concurrent/Executor;
at io.quarkus.vertx.core.runtime.QuarkusExecutorFactory.internalCreateExecutor(QuarkusExecutorFactory.java:48)
at io.quarkus.vertx.core.runtime.QuarkusExecutorFactory.createExecutor(QuarkusExecutorFactory.java:42)
at io.vertx.core.impl.VertxImpl.(VertxImpl.java:161)
at io.vertx.core.impl.VertxBuilder.vertx(VertxBuilder.java:225)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder.initialize(VertxCoreRecorder.java:236)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$VertxSupplier.get(VertxCoreRecorder.java:577)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$VertxSupplier.get(VertxCoreRecorder.java:559)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder.startServerAfterFailedStart(VertxHttpRecorder.java:208)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup.handleFailedInitialStart(VertxHttpHotReplacementSetup.java:61)
at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.startupFailed(RuntimeUpdatesProcessor.java:1145)
at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:168)
at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:455)
at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:66)
at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:140)
at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:96)
at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:132)
at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodError: org.jboss.threads.JBossExecutors.rejectingExecutor()Ljava/util/concurrent/Executor;
at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:138)
at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: java.lang.NoSuchMethodError: org.jboss.threads.JBossExecutors.rejectingExecutor()Ljava/util/concurrent/Executor;
at io.quarkus.vertx.core.runtime.QuarkusExecutorFactory.internalCreateExecutor(QuarkusExecutorFactory.java:48)
at io.quarkus.vertx.core.runtime.QuarkusExecutorFactory.createExecutor(QuarkusExecutorFactory.java:42)
at io.vertx.core.impl.VertxImpl.(VertxImpl.java:161)
at io.vertx.core.impl.VertxBuilder.vertx(VertxBuilder.java:225)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder.initialize(VertxCoreRecorder.java:236)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$VertxSupplier.get(VertxCoreRecorder.java:577)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$VertxSupplier.get(VertxCoreRecorder.java:559)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder.startServerAfterFailedStart(VertxHttpRecorder.java:208)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup.handleFailedInitialStart(VertxHttpHotReplacementSetup.java:61)
at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.startupFailed(RuntimeUpdatesProcessor.java:1145)
at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:168)
at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:455)
at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:66)
at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:140)
at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:96)
at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:132)
... 1 more
The app uses a ScheduledExecutorService, that is being created like this:
#ApplicationScoped
public class ExecutorInit {
#Produces
#ApplicationScoped
public ScheduledExecutorService getScheduledExecutorService(
#ConfigProperty(name = "systemRuntime.threadPoolSize") Integer threadPoolSize) {
return Executors.newScheduledThreadPool(threadPoolSize);
}
}
I suspect this to be involved in the error, but I am currently lacking the understanding why this is happening or what I could possibly do about it.
(if you want to try it out yourself, checkout: https://github.com/labsai/EDDI/tree/version-5)
Maven pom.xml config version:
<properties>
<dependency.version.lombok>1.18.22</dependency.version.lombok>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<jandex-maven-plugin.version>1.2.2</jandex-maven-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>2.7.5.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
<quarkus.jgit.version>1.2.0</quarkus.jgit.version>
<quarkus.microprofile.version>2.4.1.Final</quarkus.microprofile.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<failsafe-plugin.version>3.0.0-M5</failsafe-plugin.version>
<war-plugin.version>3.3.2</war-plugin.version>
</properties>
(https://github.com/labsai/EDDI/blob/version-5/pom.xml)
I still don't know the root cause of the issue described above, but here is what i did to overcome it:
added this dependency to my pom.xml
<dependency>
<groupId>org.jboss.threads</groupId>
<artifactId>jboss-threads</artifactId>
<version>3.4.2.Final</version>
<scope>provided</scope>
</dependency>
While i had other errors in my migration code, they were not being displayed anywhere until I overcame the described problem by providing this dependency.
After having fixed several other likely unrelated issues, i didn't seem to need this dependency anymore.
While this step is not a real solution, it helped my to proceed further and unveil other issues that were not being displayed at first.

Not able to run RichFaces, getting different kind of exceptions

I have developed a sample JSF application and it is running fine but I am having hardtime to run RichFaces example in JSF.
My runtime environment details: Weblogic 12.1.2, JEE 6 and JSF 2.0.
I downloaded below JARs and placed then in my WEB-INF/lib but it doesn't work.
richfaces-4.5.0.Final.jar
richfaces-a4j-4.5.0.Final.jar
richfaces-core-4.5.0.Final.jar
With these JARs, when I started my server I got class not found exception related to AtmosphereServlet so I included atmosphere-runtime-1.0.2.jar JAR and then I was getting java.lang.ClassNotFoundException: org.reflections.scanners.AbstractScanner exception.
org.reflections.scanners.AbstractScanner was not from a very popular JAR and only JAR I found for this was here. Even though I was not convinced that I should use this but still to try out I added this and then I was getting java.lang.ClassNotFoundException: org.apache.catalina.CometProcessor.
To resolve this I added this JAR. Now, I am getting java.lang.ClassNotFoundException: org.jboss.servlet.http.HttpEventServlet exception.
I am totally convinced that I am not heading in right direction because like this I may end up adding Tomcat and Jboss/Wildfly JARs in my classpath.
I searched blogs there is no clear post saying that with these JARs RichFaces works, whatever JARs were mentioned in the post I added all, at this moment I have following JARs but still have the same exception:
atmosphere-runtime-1.0.2.jar
commons-beanutils-1.8.0.jar
commons-logging-1.0.4.jar
guava-19.0.jar
richfaces-4.5.0.Final.jar
richfaces-core-4.5.0.Final.jar
catalina-comet.jar
commons-collections-3.2.jar
cssparser-0.9.18.jar
reflections-0.9.6_jboss_errai_r2.jar
richfaces-a4j-4.5.0.Final.jar
sac-1.3.jar
Another problem I am facing is that I don't know Maven so I am not able to resolve the dependencies using it, I tried below pom.xml but nothing works, it doesn't download any JAR, it simply builds some almost useless JAR.
<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>org.jvi.weblogic.jms</groupId>
<artifactId>jms-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jms-producer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>4.2.2.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<!--version>4.2.2.Final</version-->
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<!--version>4.2.2.Final</version-->
</dependency>
</dependencies>
</dependencyManagement>
</project>
Could someone please guide and help me to run RichFaces in my JSF application.
P.S.: I am able to run PrimeFaces but RichFaces dependencies looks very bad.
UPDATE 1: I also followed the official documentation and downloaded the distribution from here and had below mentioned JARs but still no help.
cssparser-0.9.18.jar
guava-19.0.jar
richfaces-a4j-4.5.17.Final.jar
richfaces-core-4.5.17.Final.jar
richfaces-page-fragments-4.5.17.Final.jar
richfaces-rich-4.5.17.Final.jar sac-1.3.jar
I had got it working. Below are the RichFaces JARs which would work with JEE 6 container and JSF 2.0; this is tested and RichFaces works with these JARs in WEB-INF/lib
richfaces-components-api-4.0.0.Final.jar
richfaces-core-api-4.0.0.Final.jar
richfaces-components-ui-4.0.0.Final.jar
richfaces-core-impl-4.0.0.Final.jar
cssparser-0.9.18.jar
sac-1.3.jar
Last 2 JARs are the dependencies.

Servlet unrecognized with 404 resource not available [duplicate]

This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 5 years ago.
i have been tring to send a request to my configured servlet from my JSP file, but i keep getting error 404 - The requested resource is not available.
i know that this question have been asked several times but it seems like none of the answer solved the problem for me.
i'm using IntelliJ ide with tomcat 9 and Java maven project.
my servlet named ControllerServlet config is:
#WebServlet(name = "ControllerServlet", urlPatterns = {"/category", "/addToCart", "/viewCart","/updateCart", "/checkout", "/purchase"},loadOnStartup = 1)
my pom.xml file have those dependencies:
<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>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
my project tree structure is like so:
pcstore
-src
-main
-java
-com
-pcStore
-controller
-ControllerServlet.java
-web
-WEB-INF
-view
-category.jsp
-web.xml
-index.jsp
-pom.xml
i was trying almost anything but ended up with no dice.
my context root is /pcStore , and i hit pcStore/category?{id} this is part of the servlet, i just want to pile up too much unnessesary code:
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//checks in which path the request is
String userPath = request.getServletPath();
// if category page is requested
if (userPath.equals("/category")) {
check if you have some collistions between your classpath jars and maven's.
maybe you should try to copy the same project and try to run a sample servlet using module source without Maven or vice versa.

Deploying embedded tomcat enabled spring-boot app using IntelliJ

I have a spring-boot based application, using embedded tomcat. I have no problem when deploying via mvn spring-boot:run goal, but I have a problems when I try to deploy using intelliJ spring-boot plugins. Important note, we have modified the default pom, turning our app into a war that could be deployed into a full tomcatTraditional Deployment, but this in development mode will be better to just deploy the app using the embedded tomcat. The problem is that basically we ended with this message when trying to run the spring boot app from intelliJ
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
... 17 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_144]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_144]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_144]
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
... 22 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_144]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_144]
... 26 common frames omitted
Do you have any ideas of why is this happening ? and how can we solve it ?
EDIT:
I am using IntelliJ IDEA 2017.2 (just in case the build is idea-IU-172.3317.76), and as a SSCCE, lets use the getting-started example of spring-boot, and lets apply the changes proposed for Traditional Deployment (the first link) we will have the following files
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Then we will have the Application.java
package hello;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
And I didn' modify the HelloController.java but just for completeness:
package hello;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
#RestController
public class HelloController {
#RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
This example runs without problem using mvn spring-boot:run but doesn't run when using the spring-boot intelliJ's plug-in
Note - this answer references Spring documentation for v 1.5.6.RELEASE (current release)
Analyses:
Running the main class from IJ is like executing your app from command line. As such, the classpath will include only compile and runtime scoped dependencies. Provided means that it'll be needed during compilation, but you expect the JDK or the container to provide it for your app at runtime:
provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
On the other hand, the spring-boot-maven-plugin uses a different classpath to execute the run goal:
By default, both the repackage and the run goals will include any provided dependencies that are defined in the project. A boot-based project should consider provided dependencies as container dependencies that are required to run the application.
Conclusion and solutions:
So it's a classpath configuration issue. As you mentioned, for war packaging or traditional deployment, you should exclude the embedded servlet container. However, to be able to run the app during development, you want the embedded container.
As a solution or work around, you have at least the following 2 options:
1) Remove the <scope>provided</scope> from the spring-boot-starter-tomcat dependency declaration. If you wanted to, you could remove that dependency altogether, as Tomcat is the default container used by spring-boot-starter-web, but perhaps it's best to leave it and add a comment, so you won't forget about it when releasing
2) A neat trick that works with IJ and would make it easier to not forget to uncomment provided before production release, is to leave the dependency as it is now, and add a maven dev profile which you can activate from IJ. This way, by default it will be provided and it can be safely packaged into a war, and only when developing and manually activating the profile it will be included. After adding the profile, reimport your maven project so you can select the profile:
<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
if you are using maven project then you need to add javax.servlet-api dependency.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
you can also download jar from http://central.maven.org/maven2/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar

Spring boot sample: Unable to start embedded container error

I am new to spring, so i downloaded jar from spring intializr for maven-web java 1.8 demo. I extracted and imported it to STS to run the main() file and I get below exception. Can some one tell me what's solution for this?
Solutions I tried from web but didn't work:
- Tried adding Hibernate-validator dependency to pom
- Tried adding spring-boot-starter-tomcat dependency to pom
STACK TRACE:
2017-01-26 12:19:32.587 INFO 3816 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2e4b8173: startup date [Thu Jan 26 12:19:32 EST 2017]; root of context hierarchy
2017-01-26 12:19:36.442 WARN 3816 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2017-01-26 12:19:36.454 ERROR 3816 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application file:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Had the same problem with release version 1.5.9 of Spring Boot.
To add to the answer by Jim Kiley, you should add the following in Maven pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.6.Final</version>
</dependency>
You can use the dependency version under properties section of Spring Boot pom.xml file (spring-boot-dependencies-1.5.9.RELEASE.pom):
<hibernate-validator.version>5.3.6.Final</hibernate-validator.version>
Located under path:
/.m2/repository/org/springframework/boot/spring-boot-dependencies/1.5.9.RELEASE/spring-boot-dependencies-1.5.9.RELEASE.pom
As the output says, you need to:
Add an implementation, such as Hibernate Validator, to the classpath
Since you're using Maven, that means you need to add the Hibernate Validator to your pom.xml's dependencies.
First of all, your pom.xml settings are correct.
spring-boot-starter-web has the dependency to hibernate-validator.
So in your project, you don't need to specify the dependency to hibernate-validator. Otherwise, what's the purpose to use maven?
So back to the resolution, the steps I did to resolve the problem are:
Goto project folder where the pom.xml is located.
Run mvn verify
The command will download the missing jar again from the repository and also check the correctness(corrupted or not) of jars in maven local repository.
If you see the warning messages similar to following:
[WARNING] error reading /home/vagrant/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.6/tomcat-embed-core-8.5.6.jar; invalid LOC header (bad signature)
[WARNING] error reading /home/vagrant/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar; invalid LOC header (bad signature)
[WARNING] error reading /home/vagrant/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.4/jackson-core-2.8.4.jar; invalid LOC header (bad signature)
Then this means that the jars downloaded by maven previously has been corrupted.
To correct this, please delete those corrupted jars and run mvn verify again to re-download them and also ensure that there's no warning for jars.
Go back to your IDE(STS or Eclipse), update your project and run the application again.
In above error the hibernate-validator-5.2.4.Final.jar is the hibernate validator that in quesion.
I met same issue and resolved it by delete these two folders under .m2
com\fasterxml --> delete it will resolve TypeResovler issue.
org\springframework --> delete it will resolve lack of validator
issue.
then the program works.
I faced the same issue while runs the application and resolved the issue by deleting the .m2 folder.
.m2/repository

Resources