SpringBoot getting started: Failed to start - java

I have created my first spring boot project and I have copied the example verbatim from springs offical website.
However, when I try to start using mvn spring:run, it fails with the following exception:
org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

You didn't say if your project is web project or not. Also since I don't see your application.properties or application.yaml. There could be so many reason and with limited amount of information on your question, I am trying to guess the answer.
If this doesn't work. update your question with more information.
If your project is not a web application project, try setting following on your application.properties
spring.main.web-application-type=none
And if you have application.yaml, set thefollowing
spring:
main:
web-application-type: none

With limited information, its hard to say whats wrong in your application. I had a similar issue and I believe it was due to corrupted jar files downloaded. I resolved referring this github issue.

There might be below reasons for ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
You might have missing web dependency in you pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
You have not annoted #SpringBootApplication to your main class:
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

Related

Can't run my Quarkus app after adding JPA

I'm trying to learn Quarkus, but after adding a JPA dependency the app doesn't initialize anymore.
This is the added dependency:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
Following are the errors I'm having:
[org.tes.uti.TestcontainersConfiguration] (build-47) Attempted to read Testcontainers configuration file at file:/home/fhb/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /home/fhb/.testcontainers.properties (No such file or directory)
After that Quarkus keeps on and gets the following error:
Caused by: java.lang.RuntimeException: io.quarkus.runtime.configuration.ConfigurationException: Model classes are defined for the default persistence unit <default> but configured datasource <default> not found: the default EntityManagerFactory will not be created. To solve this, configure the default datasource. Refer to https://quarkus.io/guides/datasource for guidance.
This is my application.properties file:
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=postgres
quarkus.datasource.password=admin
quarkus.datasource..jdbc.url=jdbc:postgresql://localhost:5432/quarkus-social
quarkus.datasource.jdbc.max-size=16
I think that Quarkus is trying to run tests and for that it needs the .testcontainers.properties file, which I've never created. Anyways I don't want to create that file in /home/fhb/, so theres a way to specify that file location?
Besides thatI would like to know if Testcontainers has something to do with unit tests, which I would like to add to my quarkus application.
Thanks in advance for your help.
I guess the problem is a small typo.
Change from
quarkus.datasource..jdbc.url=jdbc:postgresql://localhost:5432/quarkus-social
To
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/quarkus-social
If you don't specify the URL of the database and run in dev or test mode, Quarkus uses test containers to start one database for you.
There are tutorials on quarkus.io/guides/datasource.
About tests, you can use test containers or one in memory database as H2. You can find all this on Quarkus guides.

Logging system failed to initialize using configuration from 'classpath:logger/logback-spring.xml'

I use Spring boot 2.3.0.RELEASE.
application.properties
spring.profiles.active=dev
logging.config=classpath:logger/logback-spring.xml
logging.file.dir=reception-electronic-docs
logging.file.name.var=reception-electronic-docs.log
logging.file.archive.format.name=reception-electronic-docs.%d{dd-MM-yyyy}.log
Previously this code worked (Srping boot 2.2.5.RELEASE).
I use multi module structure in the project. But there, the Central pom does not manage the entire project. I create microservices.
During start up an application encounter an error:
Logging system failed to initialize using configuration from 'classpath:logger/logback-spring.xml'
java.io.FileNotFoundException: class path resource [logger/logback-spring.xml] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137)
What are any ideas to correct this?
I add an dependencies
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.2</version>
</dependency>
But I don't understand reason.
After I removed the dependency. But my app runs without errors. I'm at a loss.

Maven dependency randomly not recognized

I am working on a Java Spring Boot web application using HTML and Thymeleaf as my front end. The issue I am having is that my ThymeleafConfig class will randomly have an error when I try to run my project. I will explain in more detail below, but first here is my code.
Pom.xml dependency:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
ThymeleafConfig class:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;
#Configuration
public class ThymeleafConfig {
#Bean
public SpringSecurityDialect springSecurityDialect() {
return new SpringSecurityDialect();
}
}
So to explain further, my code will be good (according to my IDE), containing no errors on any of my lines, ready to run. I will run my application class to run my project, and I will get compilation errors.
IntelliJ will automatically open the file that has the error in it, which is my ThymeleafConfig class. When the error is present, the import statement import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect; line will be greyed out and not recognized. causing errors in the class.
To fix it, I right-click my pom.xml file -> Maven -> Reimport. This will reimport all of my dependencies and everything will go back to normal.
I also want to stress that this does not happen every time I run the application. Sometimes it will happen 3 times in a row, other times I will run it 5+ times before the error shows up again.
I have tried mvn clean which did not fix the issue. I have also moved the dependency to a different line in the pom.xml file.
edit:
Here is my Application.java class
#SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
To run the application I right click this file and click the run 'Application' button.
Spring boot already includes thymeleaf (a different version) and you are probably having multiple versions on the classpath. Spring Boot is pretty clear about thymeleaf on its documentation:
Spring boot 1.4.2's documentation on using a thymeleaf 3.0.0
By default, spring-boot-starter-thymeleaf uses Thymeleaf 2.1. If you
are using the spring-boot-starter-parent, you can use Thymeleaf 3 by
overriding the thymeleaf.version and thymeleaf-layout-dialect.version
properties, for example:
<properties>
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.3</thymeleaf-layout-dialect.version>
</properties>
...
If you are using any of the other auto-configured Thymeleaf Extras
(Spring Security, Data Attribute, or Java 8 Time) you should also
override each of their versions to one that is compatible with
Thymeleaf 3.0.
If you look at spring-boot-dependency's pom on github, the thymeleaf properties are:
<thymeleaf.version>2.1.5.RELEASE</thymeleaf.version>
<thymeleaf-extras-springsecurity4.version>2.1.2.RELEASE</thymeleaf-extras-springsecurity4.version>
<thymeleaf-extras-conditionalcomments.version>2.1.2.RELEASE</thymeleaf-extras-conditionalcomments.version>
<thymeleaf-layout-dialect.version>1.4.0</thymeleaf-layout-dialect.version>
<thymeleaf-extras-data-attribute.version>1.3</thymeleaf-extras-data-attribute.version>
<thymeleaf-extras-java8time.version>2.1.0.RELEASE</thymeleaf-extras-java8time.version>
Recap
I believe you would need to at least define the following properties (perhaps a few more to avoid a mismatch of versions?):
thymeleaf.version
thymeleaf-extras-springsecurity4.version

Spring boot RESTful service as WAR not JAR

I am in the process of creating a Java REST application, using Spring-boot. I have successfully loaded the example here and I have tried to convert the JAR file to the WAR file as presented on the Spring-boot site. I've modified my pom.xml file, adding:
<!-- other pom.xml conf -->
<packaging>war</packaging>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Then I've modified the Application.java class to initialize the servlet (this is for what Spring-boot uses to replace the web.xml file):
public class Application extends SpringBootServletInitializer {
// public static void main(String[] args) {
// new SpringApplicationBuilder(Application.class).run(args);
// }
#Bean
public ServletRegistrationBean jerseyServlet() {
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/*");
registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyInitialization.class.getName());
return registration;
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
I got my .WAR file generated, but when I deploy it on Tomcat the services are returning 404. The Tomcat logs aren't showing any errors either.
So I am not sure what it might be the problem. If you have any idea please, do share. Thanks!
Update:
Initially it wasn't working because beside the SpringBootApplication annotation to the Application class I was having other annotations too. Took those out and now Tomcat logs are showing this error.
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
I am not sure what other ContextLoader is there.
UpdateToUpdate:
Okay, after updating the jars to the latest version, using the annotation #SpringBootApplication for Application.java class, the application starts but when I am calling one of the services I receive:
java.lang.ClassNotFoundException: org.glassfish.jersey.process.internal.RequestExecutorFactory
A google search said that I should add the jersey-common and jersey-core jars, I did, but it didn't fix it. It looks like the RequestExecutorFactory.class is not packaged in the jersey-common-2.19.jar for some reason.
why do you have so many annotation in your Application class here ?
#SpringBootApplication should be sufficient to enable automatic configuration.
Try removing the others.
And put back the main method.
I think you mixed two configuration tw create a war : pre 3.0 and post 3.0 servlet container (as per the Spring Boot documentation)
EDIT :
I've found this question related to your problem.
Jersey is loading a Spring ApplicationContext. See this line of log : Spring WebApplicationInitializers detected on classpath: [com.jersey.Application#148ac084, org.glassfish.jersey.server.spring.SpringWebApplicationInitializer#7807c6d3]
Would it be possible for you to update your Spring Boot version ?
At least 1.20 so you will be able to use the spring-boot-starter-jersey. It will be a lot more easier to integrate Spring and Jersey.
You can find an example here (Spring Boot official examples).
Or you have to exclude the org.glassfish.jersey.server.spring.SpringWebApplicationInitializer of initializers

Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

I am totally new to Spring and started to do the official guides from this site:
https://spring.io/guides
I'd like to do this guide:
https://spring.io/guides/gs/scheduling-tasks/
I get the following Exception:
2014-02-14 16:25:21.614 INFO 9032 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerByCGLIB$$5b48d763] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-14 16:25:21.638 INFO 9032 --- [ main] .c.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/work/Spring/SpringTutorial/target/classes/, file:/C:/work/apache-maven-3.0.3/repo/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter/1.0.0.RC1/spring-boot-starter-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot/1.0.0.RC1/spring-boot-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-core/4.0.0.RELEASE/spring-core-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-context/4.0.0.RELEASE/spring-context-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-autoconfigure/1.0.0.RC1/spring-boot-autoconfigure-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-logging/1.0.0.RC1/spring-boot-starter-logging-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/jcl-over-slf4j/1.7.5/jcl-over-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/jul-to-slf4j/1.7.5/jul-to-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/log4j-over-slf4j/1.7.5/log4j-over-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar, file:/C:/work/apache-maven-3.0.3/repo/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-web/1.0.0.RC1/spring-boot-starter-web-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-tomcat/1.0.0.RC1/spring-boot-starter-tomcat-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/apache/tomcat/embed/tomcat-embed-core/7.0.47/tomcat-embed-core-7.0.47.jar, file:/C:/work/apache-maven-3.0.3/repo/org/apache/tomcat/embed/tomcat-embed-logging-juli/7.0.47/tomcat-embed-logging-juli-7.0.47.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-aop/4.0.0.RELEASE/spring-aop-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-beans/4.0.0.RELEASE/spring-beans-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-webmvc/4.0.0.RELEASE/spring-webmvc-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-expression/4.0.0.RELEASE/spring-expression-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-databind/2.3.1/jackson-databind-2.3.1.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-core/2.3.1/jackson-core-2.3.1.jar, file:/C:/work/apache-maven-3.0.3/repo/commons-lang/commons-lang/2.2/commons-lang-2.2.jar]
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:140)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:658)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:355)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:920)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
at hu.kumite.Application.main(Application.java:17)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:190)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:163)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
... 7 more
The application starter class is this:
#ComponentScan
#EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(ScheduledTasks.class, args);
}
}
As you can see, the main method contains a commented line. I've already done a tutorial, namely this one: https://spring.io/guides/gs/consuming-rest/
It's up and running. But I can't run the ScheduledTasks app, which is the following:
#EnableScheduling
public class ScheduledTasks {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
#Scheduled(fixedRate = 5000)
public void reportCurrentTime() {
System.out.println("The time is now " + dateFormat.format(new Date()));
}
}
I use Eclipse and run the Application.java's main as an Application.
Could someone please help me?
The scheduling guide isn't a web app so you probably have some mouldy stuff in your pom.xml from the REST guide? If you follow the instructions closely it should work. Another potential issue with the code you posted above is that your #EnableAutoConfiguration class is not used in the context, only as a main method (which may not be a problem for the scheduling guide but it probably is for a bunch of others).
A scan of the #SpringBootApplication show that it includes the following annotations:
#Configuration
#ComponentScan
#EnableAutoConfiguration
So you could do this too:
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(ScheduledTasks.class, args);
}
}
use this one in your pom.xml :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
or this one :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
I had multiple application classes in one Spring Boot project which had the web started included and wanted to avoid it configuring a web environment for one of them so I manually configured it as below:
#SpringBootApplication
public class Application
{
public static void main(String[] args)
{
new SpringApplicationBuilder(Application.class)
.web(false)
.run(args);
}
}
UPDATE for Spring Boot 2 and above:
#SpringBootApplication
public class Application
{
public static void main(String[] args)
{
new SpringApplicationBuilder(Application.class)
.web(WebApplicationType.NONE)
.run(args);
}
}
Try this
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(ScheduledTasks.class, args);
}
}
The error suggests that the application you are trying to run cannot instantiate an instance of apache tomcat. Make sure you are running the application with tomcat.
if after checking all your dependencies you experience the same problem, try to add the following in your configuration class
#Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory =
new TomcatEmbeddedServletContainerFactory();
return factory;
}
If you are using an external instance of tomcat (especially for intellij), the problem could be that the IDE is trying to start the embedded tomcat. In this case, remove the following from your pom.xml then configure the external tomcat using the 'Edit Configurations' wizard.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
if you experience this exception while using intellij and you are trying to start the application with the run button. Try starting the application from the command line instead. E.g. ensure that you are in the correct directory (directory with your pom file) assuming this is a springboot application run mvn spring-boot:run this did the trick for me.
Additionally I have also seen this error occur when your spring application depends on another application. In this case I had to start the other application first then run.
Adding the annotation #SpringBootApplication Before the starter class fixed this problem for me (so in essence, this error message can mean "you don't have a #SpringBootApplication marked class anywhere, you need at least one)
#SpringBootApplication
public class AppStarter {
public static void main(String[] args) {
SpringApplication.run(AppStarter.class, args);
}
}
I've had similar problems when the main method is on a different class than that passed to SpringApplcation.run()
So the solution would be to use the line you've commented out:
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
If you package it as a single jar and it's non web app try to load app context as below.
#SpringBootApplication
ApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class);
Or use below plugin to package as a single jar
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
you can specify the external configs by using below command to run
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
/http://docs.spring.io/spring-boot/docs/current/reference/htmlboot-features-external-config.html#boot-features-external-config-application-property-files
Note that if you are passing the properties as arguments then don't include #PropertySource("classpath:test.properties") it will override the parameters
If you run it successfully using command line gradle bootRun, while packaging it with command line gradle jar to jar file in order to run it with command line java -jar build/libs/demo.jar, unfortunately, it failed with Exception: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean, in this case, you need to use task bootRepackage of gradle plugin spring-boot to generate special runnable jar.
setup 1
$ gradle clean bootRepackage
setup 2
$ java -jar build/libs/demo.jar
A SpringApplication will attempt to create the right type of ApplicationContext on your behalf. By default, an AnnotationConfigApplicationContext or AnnotationConfigEmbeddedWebApplicationContext will be used, depending on whether you are developing a web application or not.
The algorithm used to determine a ‘web environment’ is fairly simplistic (based on the presence of a few classes). You can use setWebEnvironment(boolean webEnvironment) if you need to override the default.
It is also possible to take complete control of the ApplicationContext type that will be used by calling setApplicationContextClass(…​).
[Tip]
It is often desirable to call setWebEnvironment(false) when using SpringApplication within a JUnit test.
Adding the spring boot starter dependency fixed my error.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
This is required if you want to start the tomcat as an embeded server.
check your pom.xml is exists
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
I've had a problem like this;For lack this dependency
In my case we added the #Profile annotation newly in order to ignore the TestApplication class in production mode and the Application class in test mode.
Unfortunately, we forgot to add the following line into the application.properties files:
spring.profiles.active=test
or
spring.profiles.active=production
Without these config no profile was loaded which caused the not-so-much saying Spring Error.
This should be caused by dependency issue, in general, you need to check the dependency.
The problem it's in this class:
#ComponentScan
#EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
//SpringApplication.run(Application.class, args);
SpringApplication.run(ScheduledTasks.class, args);
}
}
The correct way to launch your application is:
#SpringBootApplication
#EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Clear repository is one possible solution.
Windows -> delete all subfolders in the maven repository:
C:\Users\YourUserName.m2\repository
I have stuck with same problem. As I didn't define Main.class and the following annotations in Spring-Boot using Maven:
#SpringBootApplication
public class Main {
public static void main(String args[]){
SpringApplication.run(Main.class, args);
}
}
Probably you missing #SpringBootApplication in your spring boot starter class.
#SpringBootApplication
public class LoginSecurityAppApplication {
public static void main(String[] args) {
SpringApplication.run(LoginSecurityAppApplication.class, args);
}
}
Problem is exclusion of starter tomcat, I tried exclude it and use vert.x, so when I integrate wit Spring Admin, started problems
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
I had this Exception in the following situation.
in my POM was properties:
<properties>
<java.version>1.8</java.version>
<!-- The main class to start by executing java -jar -->
<start-class>com.scmaer.java.microservice.Application</start-class>
<cxf.version>3.1.5</cxf.version>
<olingo.version>2.0.10</olingo.version>
<spring.boot.version>1.4.7.RELEASE</spring.boot.version>
<spring.boot.plugin.version>1.5.8.RELEASE</spring.boot.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>false</skipTests>
</properties>
and the name and path of my application class ("start-class") was wrong.
I had a similar issue and the problem was a broken maven repo jar file. In my case, the tomcat-embed-core jar file was broken. So I removed it from the maven repo and refreshed it to download again.
In my case it happen after excluding the resource folder from the pom using the following code.
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>*/*.properties</exclude>
</excludes>
</resource>
</resources>
Commenting this code started my code.
An other cause of this problem is corruption of maven repository jars so you can use the following command to solve the problem :
mvn dependency:purge-local-repository
I am using gradle, met seem issue when I have a commandLineRunner consumes kafka topics and a health check endpoint for receiving incoming hooks. I spent 12 hours to figure out, finally found that I used mybatis-spring-boot-starter with spring-boot-starter-web, and they have some conflicts. Latter I directly introduced mybatis-spring, mybatis and spring-jdbc rather than the mybatis-spring-boot-starter, and the program worked well.
hope this helps
In my case, spring configurations were not loaded as expected. On running from cmd using below command, it worked:
start java -Xms512m -Xmx1024m <and the usual parameters as needed, like PrintGC etc> -Dspring.config.location=<propertiesfiles> -jar <jar>

Categories

Resources