SpringBoot App fails to start when packaged as a jar - maven

I have a SpringBoot Application that works just fine, but when I try to package it as a jar it failes with the following error message
java -jar target/Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar
Logging
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
2016-08-04 09:13:49.743 INFO 10008 --- [ main] de.myapp.Run : Starting Run on d6889988 with PID 10008 (started by User in X:\Myapp)
2016-08-04 09:13:49.747 INFO 10008 --- [ main] de.myapp.Run : No active profile set, falling back to default profiles: default
2016-08-04 09:13:49.865 INFO 10008 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#11f66796: startup date [Thu Aug 04 09:13:49 CEST 2016]; root of context hierarchy
2016-08-04 09:13:50.479 WARN 10008 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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.
2016-08-04 09:13:50.488 ERROR 10008 --- [ main] o.s.boot.SpringApplication : Application startup failed
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:133) ~[Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at de.arbeitsagentur.amsel.Run.main(Run.java:53) [Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
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:185) ~[Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
... 8 common frames omitted
2016-08-04 09:13:50.490 INFO 10008 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/X:/Myapp/target/Amsel-1.0-SNAPSHOT-jar-with-dependencies.jar]
my Run.class with is the entry point is the following
#SpringBootApplication
#ComponentScan("de.myapp")
public class Run {
public static void main(String[] args) throws Exception{
SpringApplication.run(Run.class, args);
}
}
and this is the pom.xml which is used to generate the jar
<?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>de.myapp.amsel</groupId>
<artifactId>Amsel</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Amsel</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>de.myapp.Run</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<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>
</dependency>
</project>
any ideas what the problem could be?

Ok i found the answer myself, springboot seems to be a bit different when it comes to packaging as a jar file, so I had to add the springboot-maven plugin
http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html

Related

Is there a way to launch FXGL with SpringBoot?

I need to launch application with fxgl animations with springboot to utilize it's functionality.
I dont really know how to do it.
I tried putting initialization into different init() methods of the inheritor of the GameApplication.
I tried it like this:
#Override
protected void onPreInit() {
context = SpringApplication.run(getClass(), savedArgs);
context.getAutowireCapableBeanFactory().autowireBean(this);
super.onPreInit();
}
Or tried to mimic web version:
public class App extends Application {
private ConfigurableApplicationContext applicationContext;
#Override
public void init() {
String[] args = getParameters().getRaw().toArray(new String[0]);
this.applicationContext = new SpringApplicationBuilder()
.sources(DiplomaBaseApplication.class)
.run(args);
}
#Override
public void stop() {
this.applicationContext.close();
Platform.exit();
}
#Override
public void start(Stage stage) {
GameApplication gameApplication = new SimulationApplication();
GameApplication.embeddedLaunch(gameApplication);
}
}
#SpringBootApplication
public class DiplomaBaseApplication {
public static void main(String[] args) {
Application.launch(App.class, args);
}
}
Using javafx-weaver-spring-boot-starter.
The application started, but spring initialization ended to early end spring features and beans doesn't work:
22:08:38.879 [JavaFX Application Thread] INFO Engine - FXGL-11.17 (16.07.2021 15.46) on WINDOWS (J:11.0.10 FX:16)
22:08:38.879 [JavaFX Application Thread] INFO Engine - Source code and latest versions at: https://github.com/AlmasB/FXGL
22:08:38.880 [JavaFX Application Thread] INFO Engine - Join the FXGL chat at: https://gitter.im/AlmasB/FXGL
22:08:39.418 [FXGL Background Thread 1 ] INFO FXGLApplication - FXGL initialization took: 0,325 sec
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.7)
2022-05-13 22:08:39.900 INFO 31948 --- [lication Thread] o.s.boot.SpringApplication : Starting application using Java 11.0.10 on DESKTOP-2DKK20I with PID 31948 (started by pro56 in C:\Users\pro56\Desktop\Course)
2022-05-13 22:08:39.903 INFO 31948 --- [lication Thread] o.s.boot.SpringApplication : No active profile set, falling back to 1 default profile: "default"
2022-05-13 22:08:39.985 INFO 31948 --- [lication Thread] o.s.boot.SpringApplication : Started application in 0.425 seconds (JVM running for 1.813)
22:08:40.056 [FXGL Background Thread 1 ] INFO FXGLApplication - Game initialization took: 0,024 sec
22:08:40.852 [FXGL Background Thread 2 ] INFO UpdaterService - Your current version: 11.17
22:08:40.852 [FXGL Background Thread 2 ] INFO UpdaterService - Latest stable version: 17.1
I'm not exactly sure why this did not work for you. I tried it and it worked fine for me.
This warning is generated:
Unsupported JavaFX configuration: classes were loaded from 'unnamed module #307f6b8c'
I guess that is just how fxgl works, it runs JavaFX off the classpath in an unsupported configuration by default. I see from the FXGL documentation that it can be used as a module, so I guess in that configuration it will run a supported configuration using JavaFX modules rather than off the classpath. However, SpringBoot isn't currently coded to use the modulepath (that will happen with SpringBoot 3, I believe). So, for now, it is probably best to run everything in the unsupported configuration as demonstrated by this example.
Although in the example I placed a main method in the DemoSpringApplication for testing, the actual main class to run is not that one, it is instead the BasicSpringGameApp which extends the FXGL GameApplication.
The BasicSpringGameApp will call the SpringApplication static method to run the Spring application (which will create an instance of the Spring application).
The Spring application is separate from the FXGL GameApplication (which is internally separate from the JavaFX Application), so all of those things have different instances (just one of each), applying a separation of concerns.
src/main/java/com/example/glboot/BasicSpringGameApp.java
Extends the FXGL GameApplication. The FXGL GameApplication will (internally) launch a JavaFX application. This example will also run a spring application so that spring services will be available. The spring context is autowired into the GameApplication class so that spring services are available for use within the GameApplication class. The use of a Spring inject service is demonstrated by making calls to the UserService, which is a Spring service.
package com.example.glboot;
import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import javafx.scene.control.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
public class BasicSpringGameApp extends GameApplication {
private ConfigurableApplicationContext springContext;
#Autowired
UserService userService;
#Override
protected void initSettings(GameSettings settings) {
settings.setWidth(200);
settings.setHeight(150);
settings.setTitle("Game App");
springContext =
new SpringApplicationBuilder(DemoSpringApplication.class)
.web(WebApplicationType.NONE)
.run();
springContext
.getAutowireCapableBeanFactory()
.autowireBeanProperties(
this,
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE,
true
);
}
#Override
protected void initGame() {
String welcomeText =
"hello, " + userService.getUsername() + "\n" + userService.getWelcomeMessage();
FXGL.entityBuilder()
.at(50, 50)
.view(new Label(welcomeText))
.buildAndAttach();
}
public static void main(String[] args) {
launch(args);
}
}
src/main/resources/DemoSpringApplication.java
SpringBoot application, configures and starts up a spring services via the SpringBoot framework.
package com.example.glboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoSpringApplication {
public static void main(String[] args) {
SpringApplication.run(DemoSpringApplication.class, args);
}
}
src/main/java/com/example/glboot/UserService.java
An example user information spring service with some injected values from the spring context and application configuration properties.
package com.example.glboot;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
#Service
public class UserService {
#Value("${user.name}")
private String username;
#Value("${welcome.message}")
private String welcomeMessage;
public String getUsername() {
return username;
}
public String getWelcomeMessage() {
return welcomeMessage;
}
}
src/main/resoruces/application.properties
Spring configuration properties.
welcome.message=Welcome to FXGL Boot
pom.xml
Maven project file.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>glboot</artifactId>
<version>1.0-SNAPSHOT</version>
<name>glboot</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>com.github.almasb</groupId>
<artifactId>fxgl</artifactId>
<version>17</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version>
<configuration>
<source>18</source>
<target>18</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
console output
/Users/js732745/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=59335:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/js732745/dev/glboot/target/classes:/Users/js732745/.m2/repository/org/openjfx/javafx-controls/18.0.1/javafx-controls-18.0.1.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-controls/18.0.1/javafx-controls-18.0.1-mac.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-graphics/18.0.1/javafx-graphics-18.0.1.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-graphics/18.0.1/javafx-graphics-18.0.1-mac.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-base/18.0.1/javafx-base-18.0.1.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-base/18.0.1/javafx-base-18.0.1-mac.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-fxml/18.0.1/javafx-fxml-18.0.1.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-fxml/18.0.1/javafx-fxml-18.0.1-mac.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-media/18.0.1/javafx-media-18.0.1.jar:/Users/js732745/.m2/repository/org/openjfx/javafx-media/18.0.1/javafx-media-18.0.1-mac.jar:/Users/js732745/.m2/repository/com/github/almasb/fxgl/17/fxgl-17.jar:/Users/js732745/.m2/repository/com/github/almasb/fxgl-core/17/fxgl-core-17.jar:/Users/js732745/.m2/repository/com/gluonhq/attach/audio/4.0.9/audio-4.0.9.jar:/Users/js732745/.m2/repository/com/github/almasb/fxgl-io/17/fxgl-io-17.jar:/Users/js732745/.m2/repository/com/gluonhq/attach/storage/4.0.9/storage-4.0.9.jar:/Users/js732745/.m2/repository/com/gluonhq/attach/util/4.0.9/util-4.0.9.jar:/Users/js732745/.m2/repository/com/github/almasb/fxgl-entity/17/fxgl-entity-17.jar:/Users/js732745/.m2/repository/com/github/almasb/fxgl-scene/17/fxgl-scene-17.jar:/Users/js732745/.m2/repository/com/github/almasb/fxgl-gameplay/17/fxgl-gameplay-17.jar:/Users/js732745/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.13.2/jackson-annotations-2.13.2.jar:/Users/js732745/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.13.2.1/jackson-databind-2.13.2.1.jar:/Users/js732745/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.13.2/jackson-core-2.13.2.jar:/Users/js732745/.m2/repository/com/gluonhq/attach/lifecycle/4.0.9/lifecycle-4.0.9.jar:/Users/js732745/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.5.32/kotlin-stdlib-1.5.32-modular.jar:/Users/js732745/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/Users/js732745/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.6.21/kotlin-stdlib-common-1.6.21.jar:/Users/js732745/.m2/repository/org/springframework/boot/spring-boot-starter/2.6.7/spring-boot-starter-2.6.7.jar:/Users/js732745/.m2/repository/org/springframework/boot/spring-boot/2.6.7/spring-boot-2.6.7.jar:/Users/js732745/.m2/repository/org/springframework/spring-context/5.3.19/spring-context-5.3.19.jar:/Users/js732745/.m2/repository/org/springframework/spring-aop/5.3.19/spring-aop-5.3.19.jar:/Users/js732745/.m2/repository/org/springframework/spring-beans/5.3.19/spring-beans-5.3.19.jar:/Users/js732745/.m2/repository/org/springframework/spring-expression/5.3.19/spring-expression-5.3.19.jar:/Users/js732745/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.6.7/spring-boot-autoconfigure-2.6.7.jar:/Users/js732745/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.6.7/spring-boot-starter-logging-2.6.7.jar:/Users/js732745/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar:/Users/js732745/.m2/repository/ch/qos/logback/logback-core/1.2.11/logback-core-1.2.11.jar:/Users/js732745/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.17.2/log4j-to-slf4j-2.17.2.jar:/Users/js732745/.m2/repository/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar:/Users/js732745/.m2/repository/org/slf4j/jul-to-slf4j/1.7.36/jul-to-slf4j-1.7.36.jar:/Users/js732745/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/js732745/.m2/repository/org/springframework/spring-core/5.3.19/spring-core-5.3.19.jar:/Users/js732745/.m2/repository/org/springframework/spring-jcl/5.3.19/spring-jcl-5.3.19.jar:/Users/js732745/.m2/repository/org/yaml/snakeyaml/1.29/snakeyaml-1.29.jar:/Users/js732745/.m2/repository/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar com.example.glboot.BasicSpringGameApp
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.7)
2022-05-13 15:54:30.381 INFO 32226 --- [ main] com.example.glboot.BasicSpringGameApp : Starting BasicSpringGameApp using Java 18.0.1.1 on C02ZX2NFMD6T with PID 32226 (/Users/js732745/dev/glboot/target/classes started by js732745 in /Users/js732745/dev/glboot)
2022-05-13 15:54:30.384 INFO 32226 --- [ main] com.example.glboot.BasicSpringGameApp : No active profile set, falling back to 1 default profile: "default"
2022-05-13 15:54:30.772 INFO 32226 --- [ main] com.example.glboot.BasicSpringGameApp : Started BasicSpringGameApp in 0.675 seconds (JVM running for 0.988)
2022-05-13 15:54:30.835 WARN 32226 --- [JavaFX-Launcher] javafx : Unsupported JavaFX configuration: classes were loaded from 'unnamed module #307f6b8c'
15:54:31.118 [JavaFX Application Thread] INFO Engine - FXGL-17 (31.12.2021 18.16) on MAC (J:18.0.1.1 FX:18.0.1)
15:54:31.119 [JavaFX Application Thread] INFO Engine - Source code and latest versions at: https://github.com/AlmasB/FXGL
15:54:31.119 [JavaFX Application Thread] INFO Engine - Ask questions and discuss at: https://github.com/AlmasB/FXGL/discussions
15:54:31.119 [JavaFX Application Thread] INFO Engine - Join the FXGL chat at: https://gitter.im/AlmasB/FXGL
15:54:31.534 [FXGL Background Thread 1 ] WARN FXGL.DefaultMenu - FXGLDefaultMenu is not designed for resolutions < 800x600
15:54:31.686 [FXGL Background Thread 1 ] INFO FXGLApplication - FXGL initialization took: 0.399 sec
15:54:31.757 [FXGL Background Thread 4 ] INFO FXGLApplication - Game initialization took: 0.005 sec
15:54:32.035 [FXGL Background Thread 2 ] INFO UpdaterService - Your current version: 17
15:54:32.036 [FXGL Background Thread 2 ] INFO UpdaterService - Latest stable version: 17.1

Log4J2 not working on Spring Boot on many levels

I am trying to use log4j2 in a Spring Boot application, but it is going wrong on several levels.
This is a very simple Hello World application, just trying to get things working before I try it in production code. It is just a simple Initializr-generated Spring Boot application, with no added dependencies.
Problem #1 is that I am getting the following warnings, so I tried adding exclusions, but so far nothing is working
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/vgray/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/vgray/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.13.3/log4j-slf4j-impl-2.13.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Here is the pom:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sample</groupId>
<artifactId>log4j2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>log4j2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<log4j2.version>2.13.3</log4j2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Problem #2 (I assume related) is that I have log4j2.xml in my src/main/resources dir, but it seems to be ignored.
Here is the log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Properties>
<Property name="basePath">E:\dev\log4j2\\logs</Property>
</Properties>
<Appenders>
<RollingFile name="fileLogger" fileName="${basePath}/app-info.log" filePattern="${basePath}/app-info-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="Log4j2Application" level="debug" additivity="true">
<appender-ref ref="fileLogger" level="debug" />
</Logger>
<Root level="debug" additivity="false">
<appender-ref ref="console" />
</Root>
</Loggers>
</Configuration>
I am assuming it is ignored, because the pattern is supposed to be MM-dd..., but the log messages are logging differently.
Here is my entire Spring Boot program:
package com.vgray.sample.log4j2;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Log4j2Application {
private static final Logger logger = LogManager.getLogger("Log4j2Application");
public static void main(String[] args) {
logger.trace("A TRACE Message");
logger.debug("A DEBUG Message");
logger.info("An INFO Message");
logger.warn("A WARN Message");
logger.error("An ERROR Message");
logger.error("Error Message Logged !!!", new NullPointerException("NullError"));
SpringApplication.run(Log4j2Application.class, args);
}
}
Here is my entire log
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/vgray/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/vgray/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.13.3/log4j-slf4j-impl-2.13.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
21:20:18.355 [main] DEBUG Log4j2Application - A DEBUG Message
21:20:18.358 [main] INFO Log4j2Application - An INFO Message
21:20:18.358 [main] WARN Log4j2Application - A WARN Message
21:20:18.358 [main] ERROR Log4j2Application - An ERROR Message
21:20:18.361 [main] ERROR Log4j2Application - Error Message Logged !!!
java.lang.NullPointerException: NullError
at com.vgray.sample.log4j2.Log4j2Application.main(Log4j2Application.java:19)
21:20:18.531 [restartedMain] DEBUG Log4j2Application - A DEBUG Message
21:20:18.532 [restartedMain] INFO Log4j2Application - An INFO Message
21:20:18.532 [restartedMain] WARN Log4j2Application - A WARN Message
21:20:18.532 [restartedMain] ERROR Log4j2Application - An ERROR Message
21:20:18.532 [restartedMain] ERROR Log4j2Application - Error Message Logged !!!
java.lang.NullPointerException: NullError
at com.vgray.sample.log4j2.Log4j2Application.main(Log4j2Application.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.2)
2021-02-28 21:20:19.087 INFO 69604 --- [ restartedMain] c.v.sample.log4j2.Log4j2Application : Starting Log4j2Application using Java 11.0.3 on DESKTOP-AM6DIPA with PID 69604 (E:\dev\log4j2\target\classes started by vgray in e:\dev\log4j2)
2021-02-28 21:20:19.089 INFO 69604 --- [ restartedMain] c.v.sample.log4j2.Log4j2Application : No active profile set, falling back to default profiles: default
2021-02-28 21:20:19.174 INFO 69604 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-02-28 21:20:19.174 INFO 69604 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-02-28 21:20:20.352 INFO 69604 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-02-28 21:20:20.364 INFO 69604 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-28 21:20:20.364 INFO 69604 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-28 21:20:20.451 INFO 69604 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-28 21:20:20.451 INFO 69604 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1275 ms
2021-02-28 21:20:20.657 INFO 69604 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-28 21:20:20.829 INFO 69604 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2021-02-28 21:20:20.862 INFO 69604 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-02-28 21:20:20.876 INFO 69604 --- [ restartedMain] c.v.sample.log4j2.Log4j2Application : Started Log4j2Application in 2.33 seconds (JVM running for 3.718)
Sorry, cannot reproduce/works like a charm:
https://github.com/xerx593/soq66415875
Uses configuration from src/main/resources/log4j2.xml.
Prints DEBUG log messages to:
console as to
${working_dir}/app-info.log
(according to configuration) and exits.
Tiny(iest) changes to original Post:
removed (redundant) <log4j2.version/> from pom.xml (2.13.3 - same version as managed by spring-boot-starter:2.4.2)
relative addressing of the log file.
Output:
[DEBUG] 03-01 05:20:38.923 [main] Log4j2Application - A DEBUG Message
[INFO ] 03-01 05:20:38.938 [main] Log4j2Application - An INFO Message
[WARN ] 03-01 05:20:38.938 [main] Log4j2Application - A WARN Message
[ERROR] 03-01 05:20:38.938 [main] Log4j2Application - An ERROR Message
[ERROR] 03-01 05:20:38.938 [main] Log4j2Application - Error Message Logged !!!
java.lang.NullPointerException: NullError
at com.example.demo.Log4j2Application.main(Log4j2Application.java:18) [classes/:?]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.2)
[INFO ] 03-01 05:20:39.839 [main] Log4j2Application - Starting Log4j2Application using Java 11.0.10 on rihanna with PID 9892 (D:\DEV\projects\soq66415875\target\classes started by xerx in D:\DEV\projects\soq66415875)
[DEBUG] 03-01 05:20:39.839 [main] Log4j2Application - Running with Spring Boot v2.4.2, Spring v5.3.3
[INFO ] 03-01 05:20:39.839 [main] Log4j2Application - No active profile set, falling back to default profiles: default
[DEBUG] 03-01 05:20:39.839 [main] SpringApplication - Loading source class com.example.demo.Log4j2Application
...
.... tons of debug messages, and finally:
...
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration
[INFO ] 03-01 05:20:40.889 [main] Log4j2Application - Started Log4j2Application in 1.744 seconds (JVM running for 3.669)
[DEBUG] 03-01 05:20:40.904 [SpringContextShutdownHook] AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#54ec8cc9, started on Mon Mar 01 05:20:39 CET 2021
[DEBUG] 03-01 05:20:40.904 [SpringContextShutdownHook] AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown
;) (or it is one/both of the tiny changes, or other "side effects")
I think both your problems arouse because you were not excluding the logging dependency from the spring-boot-starter-parent which you were including as the parent dependency. You need to exclude it from starter parent like:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Your pom.xml was excluding it from spring-boot-starter instead.

Getting a termination after adding Springs LDAP-Core

I built a simple app with Spring Boot.
Test.java
package Test;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.scheduling.annotation.*;
#SpringBootApplication
#EnableScheduling
public class App
{
public static void main( String[] args )
{
SpringApplication.run (App.class, args);
}
}
pom.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>Test</groupId>
<artifactId>Test</artifactId>
<version>1.0</version>
<name>Test</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Starts as expected.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.RELEASE)
2021-01-22 21:10:08.438 INFO 11932 --- [ main] Test.App : Starting App on ASPIRE with PID 11932 (/MvnTest/Test/target/classes started by ch in /data/projects/MvnTest/Test)
2021-01-22 21:10:08.441 INFO 11932 --- [ main] Test.App : No active profile set, falling back to default profiles: default
2021-01-22 21:10:09.421 INFO 11932 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-01-22 21:10:09.432 INFO 11932 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-01-22 21:10:09.432 INFO 11932 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2021-01-22 21:10:09.496 INFO 11932 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-01-22 21:10:09.496 INFO 11932 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 981 ms
2021-01-22 21:10:09.679 INFO 11932 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-22 21:10:09.820 INFO 11932 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: b1d1aca3-b55e-4d71-aac6-9e33e4d082bd
2021-01-22 21:10:09.889 INFO 11932 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#5a0bef24, org.springframework.security.web.context.SecurityContextPersistenceFilter#1bb740f2, org.springframework.security.web.header.HeaderWriterFilter#29fa6b65, org.springframework.security.web.csrf.CsrfFilter#3ac3f6f, org.springframework.security.web.authentication.logout.LogoutFilter#51b01550, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#3289079a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#672a1c62, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#6468a7b6, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#708f018e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#61f6d381, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#5f95f1e1, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#2f860823, org.springframework.security.web.session.SessionManagementFilter#47406941, org.springframework.security.web.access.ExceptionTranslationFilter#6504a875, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#1d247525]
2021-01-22 21:10:09.903 INFO 11932 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2021-01-22 21:10:09.953 INFO 11932 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-01-22 21:10:09.957 INFO 11932 --- [ main] Test.App : Started App in 1.876 seconds (JVM running for 2.209)
I try to add a dependency for LDAP.
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
Then it terminates immediately.
21:05:32.453 [background-preinit] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
21:05:32.456 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.17.Final
21:05:32.463 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
21:05:32.465 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
21:05:32.466 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
21:05:32.466 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
21:05:32.467 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
21:05:32.551 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
Any ideas how to make it start normally?
I suspect you are have version number clashing.
when creating a spring boot project i suggest you use the spring boot initializer. Here you can select what dependencies you want. Then they generate a project for you and when you look into the pom, you will se that there is a parent pom declared at the top.
That usually looks like this and contains the version for that release of spring boot:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
</parent>
This parent is essential because spring boot is a framework, so each release of the framework includes dependencies with specific version numbers. The parent pom makes sure that all the dependencies are of version numbers that work together. You can read about how a java project in spring is setup here.
Which also means that when you declare other spring dependencies you can omit the
version numbers, since the parent pom will pick a version number that works well with that version of spring boot.
// no need for version numbering it gets fetched from the parent
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
So when you declare the ldap dependency you can also omit the version number.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-ldap</artifactId>
</dependency>
But as mentioned in the top, use the initializer to create a spring boot project. Super easy.

Repository class require bean entityManagerFactory could not be found

I am making a angular + spring application in and was trying to deploy it in same server. when i created back-end separately it worked fine all the process was working. but when i copied my angular project in spring project and configured in pom.xml and updated my maven and tried running the project it started giving me below error
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-24 16:13:29.074 INFO 3136 --- [ main]
com.accounts.rtgsneft.Application : Starting Application on HO-W-
Ankushpc with PID 3136 (D:\Rocky\workspaces\acounts-projects\rtgs-neft-
v1.0\target\classes started by Rocky in D:\Rocky\workspaces\acounts-
projects\rtgs-neft-v1.0)
2019-09-24 16:13:29.076 INFO 3136 --- [ main]
com.accounts.rtgsneft.Application : No active profile set, falling
back to default profiles: default
2019-09-24 16:13:29.530 INFO 3136 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
repositories in DEFAULT mode.
2019-09-24 16:13:29.584 INFO 3136 --- [ main] .
s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository
scanning in 48ms. Found 4 repository interfaces.
2019-09-24 16:13:29.910 INFO 3136 --- [ main]
trationDelegate$BeanPostProcessorChecker : Bean
'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$3c9c44bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-24 16:13:30.143 INFO 3136 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8086 (http)
2019-09-24 16:13:30.160 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-24 16:13:30.160 INFO 3136 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-24 16:13:30.264 INFO 3136 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-24 16:13:30.264 INFO 3136 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1158 ms
2019-09-24 16:13:30.399 WARN 3136 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryController': Unsatisfied dependency expressed through field 'beneficiaryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryMasterServiceImpl': Unsatisfied dependency expressed through field 'beneficiaryRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beneficiaryMasterRepository': Cannot create inner bean '(inner bean)#3ac04654' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3ac04654': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2019-09-24 16:13:30.402 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-09-24 16:13:30.416 INFO 3136 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run
your application with 'debug' enabled.
2019-09-24 16:13:30.465 ERROR 3136 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field beneficiaryRepo in
com.accounts.rtgsneft.service.BeneficiaryMasterServiceImpl required a bean
named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
i have tried all the solution on stack but none of them worked.
this are the solutions i have tried:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled
Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument
bean named 'entityManagerFactory' could not be found
Spring Boot - repository field required a bean named 'entityManagerFactory' that could not be found
Field repository required a bean named 'entityManagerFactory' that could not be found
Spring data jpa- No bean named 'entityManagerFactory' is defined; Injection of autowired dependencies failed
this is the solution i tried while debugging.
getDeclaredConstructors0(boolean)- line not available during tomcat startup in debug mode
my 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.accounts.rtgsneft</groupId>
<artifactId>rtgsneft</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rtgsneft</name>
<description>Gold's Gym Account department rtgs neft software</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/resources/static/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/rtgs-neft/dist/rtgs-neft</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
my BeneficiaryController .java
package com.accounts.rtgsneft.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
import com.accounts.rtgsneft.service.BeneficiaryMasterService;
/**
* #author Rocky
*
*/
#CrossOrigin(origins = "*", maxAge = 3600)
#RestController
#RequestMapping("beneficiary")
public class BeneficiaryController {
#Autowired
BeneficiaryMasterService beneficiaryService;
#GetMapping("all-beneficiary")
public ResponseEntity<?> getBeneficiaries() {
List<BeneficiaryMaster> beneficiaries = beneficiaryService.gettingBeneficiaries();
return new ResponseEntity<>(beneficiaries, HttpStatus.OK);
}
#PostMapping("new-beneficiary")
public ResponseEntity<?> postBeneficiary(#RequestBody BeneficiaryMaster beneficiary) {
boolean beneficiaryRegistered = beneficiaryService.registerBeneficiary(beneficiary);
return new ResponseEntity<>(beneficiaryRegistered, HttpStatus.OK);
}
#PostMapping("single-beneficiary")
public ResponseEntity<?> selectedBeneficiary(#RequestBody BeneficiaryMaster beneficiaryOBJ) {
BeneficiaryMaster beneficiary = beneficiaryService.getBeneficiary(beneficiaryOBJ.getAccountNumber());
return new ResponseEntity<>(beneficiary, HttpStatus.OK);
}
}
my BeneficiaryMasterService.java
package com.accounts.rtgsneft.service;
import java.util.List;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
public interface BeneficiaryMasterService {
List<BeneficiaryMaster> gettingBeneficiaries();
boolean registerBeneficiary(BeneficiaryMaster beneficiary);
BeneficiaryMaster getBeneficiary(Long accountNumber);
}
my BeneficiaryMasterServiceImpl.java
package com.accounts.rtgsneft.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
import com.accounts.rtgsneft.repos.BeneficiaryMasterRepository;
#Service
public class BeneficiaryMasterServiceImpl implements BeneficiaryMasterService {
#Autowired
BeneficiaryMasterRepository beneficiaryRepo;
#Override
public List<BeneficiaryMaster> gettingBeneficiaries() {
return beneficiaryRepo.findAll();
}
#Override
public boolean registerBeneficiary(BeneficiaryMaster beneficiary) {
boolean benficiaryStatusFlag = false;
BeneficiaryMaster benficiaryStatus= beneficiaryRepo.save(beneficiary);
if(benficiaryStatus != null ) {
benficiaryStatusFlag = true;
}
return benficiaryStatusFlag;
}
#Override
public BeneficiaryMaster getBeneficiary(Long accountNumber) {
return beneficiaryRepo.getOne(accountNumber);
}
}
my BeneficiaryMasterRepository.java
package com.accounts.rtgsneft.repos;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
#Repository
public interface BeneficiaryMasterRepository extends
JpaRepository<BeneficiaryMaster, Long> {}
I hope this much data is enough to find out the issue.
If there is any other solution please recommend it to me.
I'm using spring 2.17
I want to deploy the application war file in tomcat and before doing that i have to test it for checking whether it's still working or not.
Spring Data JPA by default looks for an EntityManagerFactory named entityManagerFactory. Check out this part of the Javadoc of EnableJpaRepositories or Table 2.1 of the Spring Data JPA documentation.
That means that you either have to rename your emf bean to entityManagerFactory or change your Spring configuration to:
(if you are using XML)
or
#EnableJpaRepositories(basePackages="your.package", entityManagerFactoryRef="emf")
(if you are using Java Config)

Spark maven dependency breaks down sprint-boot application

I have a spring-boot application with Swing GUI. It just work! But as soon as I add spark 2.0 dependency to the pom.xml file it shows the following error message during start up and will not start!
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/ehsun7b/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/ehsun7b/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.1.RELEASE)
2016-10-21 00:02:23.795 INFO 1642 --- [ main] edu.mfldclin.mcrf.vakilabad.Application : Starting Application on Ehsuns-MacBook-Pro.local with PID 1642 (/Users/ehsun7b/NetBeansProjects/vakilabad/target/classes started by ehsun7b in /Users/ehsun7b/NetBeansProjects/vakilabad)
2016-10-21 00:02:23.797 INFO 1642 --- [ main] edu.mfldclin.mcrf.vakilabad.Application : No active profile set, falling back to default profiles: default
2016-10-21 00:02:23.839 INFO 1642 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#67c27493: startup date [Fri Oct 21 00:02:23 MYT 2016]; root of context hierarchy
2016-10-21 00:02:24.290 INFO 1642 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-10-21 00:02:25.650 INFO 1642 --- [ main] e.m.mcrf.vakilabad.log.LogService : LogService init.
2016-10-21 00:02:25.767 INFO 1642 --- [ main] e.mfldclin.mcrf.vakilabad.log.LogFrame : Adding LogFrame instance to the LogMonitors of LogService: edu.mfldclin.mcrf.vakilabad.log.LogFrame[frame0,0,2,511x390,invalid,hidden,layout=java.awt.BorderLayout,title=Log since 2016-10-21T00:02:25.750,resizable,normal,defaultCloseOperation=DISPOSE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,511x368,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
2016-10-21 00:02:25.897 WARN 1642 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties': 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.
2016-10-21 00:02:25.897 INFO 1642 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-10-21 00:02:25.902 INFO 1642 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2016-10-21 00:02:25.906 ERROR 1642 --- [ 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
This the dependency that I add:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.0.1</version>
</dependency>
I am seeing in spark-core_2.11-2.0.1.jar\META-INF\DEPENDENCIES and there is:
// ------------------------------------------------------------------
// Transitive dependencies of this project determined from the
// maven pom organized by organization.
// ------------------------------------------------------------------
Spark Project Core
From: 'an unknown organization'
...
...
- Bean Validation API (http://beanvalidation.org) javax.validation:validation-api:jar:1.1.0.Final
License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt)
and with #EnableAutoConfiguration spring probably see this dependency on classpath and try to find implementation of Java specification for Bean Validation. (Some interesting reading for spring validation).
In my opinion it is because spark uses jersey as a way how to show us information of job status and so on jersey bean-validation - but I am not quite sure about this statement.
But you can fix this issue by providing implementation of Bean Validation - just add dependency of implementation to maven.
Hibernate-validator
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.0.Final</version>
</dependency>
or much more quicker (source) Apache BeanValidation.
<!-- https://mvnrepository.com/artifact/org.apache.bval/bval-jsr303 -->
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<version>0.5</version>
</dependency>
SOLUTION is in the comments! (exclusion of validation API)

Resources