Log4J2 not working on Spring Boot on many levels - spring-boot

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.

Related

ShedLock with Spring boot with couchbase

Given my Spring boot application code:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.couchbase.client.java.Bucket;
import net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
#SpringBootApplication
#EnableScheduling
#EnableSchedulerLock(defaultLockAtMostFor = "10m")
public class MythoughtsApplication {
public static void main(String[] args) {
SpringApplication.run(MythoughtsApplication.class, args);
}
#Bean
public CouchbaseLockProvider lockProvider(Bucket bucket) {
return new CouchbaseLockProvider(bucket);
}
}
pom.xml
using the latest shedlock in the below pom.xml 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.7.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.guru</groupId>
<artifactId>mythoughts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mythoughts</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
</dependency>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>core-io</artifactId>
<version>2.3.1</version>
</dependency>
**<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
**<version>4.37.0</version>**
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-couchbase-javaclient3</artifactId>
**<version>4.37.0</version>**
</dependency>**
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
couchbase Connection file
#Configuration
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
#Override
public String getConnectionString() {
// TODO Auto-generated method stub
return "127.0.0.1";
}
#Override
public String getUserName() {
// TODO Auto-generated method stub
return "admin";
}
#Override
public String getPassword() {
// TODO Auto-generated method stub
return "1234";
}
#Override
public String getBucketName() {
// TODO Auto-generated method stub
return "admin";
}
}
controller file
import org.springframework.scheduling.annotation.Scheduled;
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.guru.mythoughts.service.UserService;
import net.javacrumbs.shedlock.core.LockAssert;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
#RestController
public class UserController {
#Scheduled(cron = "*/5 * * * * *")
#SchedulerLock(name = "scheduledTaskName", lockAtMostFor = "PT5M", lockAtLeastFor = "PT4M")
public void scheduledTask() {
LockAssert.assertLocked();
System.out.println("cloked");
}
}
Output with error:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-06-21 17:36:01.346 INFO 21152 --- [ main] c.zzz.mythoughts.MyApplication : Starting MythoughtsApplication using Java 1.8.0_271 on DESKTOP-O8IM34ASBST with PID 21152 (C:\Users\G\Downloads\mythoughts\target\classes started by in C:\Users\G\Downloads\mythoughts)
2022-06-21 17:36:01.350 INFO 21152 --- [ main] c.zzz.mythoughts.MythoughtsApplication : No active profile set, falling back to 1 default profile: "default"
2022-06-21 17:36:01.889 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
2022-06-21 17:36:02.033 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 139 ms. Found 0 Couchbase repository interfaces.
2022-06-21 17:36:02.039 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
2022-06-21 17:36:02.061 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 22 ms. Found 1 Couchbase repository interfaces.
2022-06-21 17:36:02.504 INFO 21152 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-06-21 17:36:02.514 INFO 21152 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-06-21 17:36:02.514 INFO 21152 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-06-21 17:36:02.751 INFO 21152 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-06-21 17:36:02.751 INFO 21152 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1346 ms
2022-06-21 17:36:03.445 INFO 21152 --- [ cb-events] com.couchbase.core : [com.couchbase.core][CoreCreatedEvent] {"clientVersion":"3.3.0","clientGitHash":"${buildNumber}","coreVersion":"2.3.1","coreGitHash":"${buildNumber}","userAgent":"couchbase-java/3.3.0 (Windows 10 10.0 amd64; Java HotSpot(TM) 64-Bit Server VM 1.8.0_271-b09)","maxNumRequestsInRetry":32768,"ioEnvironment":{"nativeIoEnabled":true,"eventLoopThreadCount":4,"eventLoopGroups":["NioEventLoopGroup"]},"ioConfig":{"captureTraffic":[],"mutationTokensEnabled":true,"networkResolution":"auto","dnsSrvEnabled":true,"tcpKeepAlivesEnabled":true,"tcpKeepAliveTimeMs":60000,"configPollIntervalMs":2500,"kvCircuitBreakerConfig":"disabled","queryCircuitBreakerConfig":"disabled","viewCircuitBreakerConfig":"disabled","searchCircuitBreakerConfig":"disabled","analyticsCircuitBreakerConfig":"disabled","managerCircuitBreakerConfig":"disabled","eventingCircuitBreakerConfig":"disabled","backupCircuitBreakerConfig":"disabled","numKvConnections":1,"maxHttpConnections":12,"idleHttpConnectionTimeoutMs":4500,"configIdleRedialTimeoutMs":300000,"memcachedHashingStrategy":"StandardMemcachedHashingStrategy"},"compressionConfig":{"enabled":true,"minRatio":0.83,"minSize":32},"securityConfig":{"tlsEnabled":false,"nativeTlsEnabled":true,"hostnameVerificationEnabled":true,"trustCertificates":null,"trustManagerFactory":null,"ciphers":[]},"timeoutConfig":{"kvMs":2500,"kvDurableMs":10000,"managementMs":75000,"queryMs":75000,"viewMs":75000,"searchMs":75000,"analyticsMs":75000,"connectMs":10000,"disconnectMs":10000,"eventingMs":75000,"backupMs":75000},"loggerConfig":{"customLogger":null,"fallbackToConsole":false,"consoleLogLevel":{"name":"INFO","resourceBundleName":"sun.util.logging.resources.logging","localizedName":"INFO"},"consoleLoggerFormatter":"DefaultLoggerFormatter","disableSlf4j":false,"loggerName":"CouchbaseLogger","diagnosticContextEnabled":false},"orphanReporterConfig":{"emitIntervalMs":10000,"sampleSize":10,"queueLength":1024,"enabled":true},"thresholdLoggingTracerConfig":{"enabled":true,"emitIntervalMs":10000,"sampleSize":10,"queueLength":1024,"kvThresholdMs":500,"queryThresholdMs":1000,"searchThresholdMs":1000,"analyticsThresholdMs":1000,"viewThresholdMs":1000},"loggingMeterConfig":{"enabled":true,"emitIntervalMs":600000},"retryStrategy":"BestEffortRetryStrategy","requestTracer":"ThresholdLoggingTracer","meter":"LoggingMeter","numRequestCallbacks":0,"scheduler":"ParallelScheduler","schedulerThreadCount":8,"transactionsConfig":{"durabilityLevel":"MAJORITY","timeoutMs":15000,"cleanupConfig":{"runLostAttemptsCleanupThread":true,"runRegularAttemptsCleanupThread":true,"cleanupWindowMs":60000,"cleanupSet":""},"numAtrs":1024,"metadataCollection":"none","scanConsistency":"none"}} {"coreId":"0xa407cf8700000001","seedNodes":[{"address":"127.0.0.1"}]}
2022-06-21 17:36:03.445 INFO 21152 --- [ cb-events] com.couchbase.transactions : [com.couchbase.transactions][TransactionsStartedEvent] Transactions successfully initialised, regular cleanup enabled=true, lost cleanup enabled=true
2022-06-21 17:36:03.452 INFO 21152 --- [ cb-events] com.couchbase.node : [com.couchbase.node][NodeConnectedEvent] Node connected {"coreId":"0xa407cf8700000001","managerPort":"8091","remote":"127.0.0.1"}
2022-06-21 17:36:03.985 WARN 21152 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lockProvider' defined in com.guru.mythoughts.MythoughtsApplication: Unsatisfied dependency expressed through method 'lockProvider' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.couchbase.client.java.Bucket' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2022-06-21 17:36:04.026 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup : [com.couchbase.transactions.cleanup][LogEvent] Waiting for 1 regular background threads to exit
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] c.c.transactions.cleanup.regular : [com.couchbase.transactions.cleanup.regular][LogEvent] Stopping background cleanup thread for transactions from this client
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup.lost : [com.couchbase.transactions.cleanup.lost][LogEvent] Client d9110 has been told to cancel
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup.lost : [com.couchbase.transactions.cleanup.lost][LogEvent] Client d9110 stopping lost cleanup process, 0 threads running
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup.lost : [com.couchbase.transactions.cleanup.lost][LogEvent] Client d9110 stopped lost cleanup process and removed client from client records
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup : [com.couchbase.transactions.cleanup][LogEvent] Background threads have exitted
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.node : [com.couchbase.node][NodeDisconnectedEvent][667us] Node disconnected {"coreId":"0xa407cf8700000001","managerPort":"8091","remote":"127.0.0.1"}
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.core : [com.couchbase.core][ShutdownCompletedEvent][19ms] Completed shutdown and closed all open buckets {"coreId":"0xa407cf8700000001"}
2022-06-21 17:36:04.118 INFO 21152 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-06-21 17:36:04.130 INFO 21152 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-21 17:36:04.157 ERROR 21152 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method lockProvider in com.guru.mythoughts.MythoughtsApplication required a bean of type 'com.couchbase.client.java.Bucket' that could not be found.
Action:
Consider defining a bean of type 'com.couchbase.client.java.Bucket' in your configuration.
I have given sample code and when I tried to run the application I am getting the above error. I have scheduled a method in controller and it should run for every 5 seconds.
I have followed the above in the given below link
https://gitcode.net/mirrors/lukas-krecan/ShedLock/-/tree/master/providers/couchbase
How can i solve this error?
Autowired the Cluster class and used the cluster to get the bucket details with bean creation in main class which return the bucket object. please see the same code and it is working fine.
#Autowired
Cluster cluster;
#Bean
public Bucket getBucket() {
return cluster.bucket("bucket");
}
}
Another option is to have a Cluster argument to your getBucket() bean method.
#Bean
public Bucket getBucket(Cluster cluster){
return cluster.bucket("myBucket");
}

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.

JMS not starting in Spring Boot application

I developed a spring boot application which send and listen message in Activemq using JMS, but while running application, JMS is not getting started by spring boot
This is mainclass, Application.java
#SpringBootApplication
#EnableJms
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
Configuration class: Config.java
#Configuration
public class Config {
#Bean
public Queue queue() {
return new ActiveMQQueue("inmemory.queue");
}
#Bean
public JmsTemplate jmsTemplate() {
return new JmsTemplate(activeMQConnectionFactory());
}
}
Listener class is used to listen to the queue: Listener.java
#Component
public class Listener {
#JmsListener(destination = "inmemory.queue")
public void listener(String message) {
System.out.println("message received" + message);
}
}
Producer class is used to send message to queue from controller: Producer.java
#RestController
public class Producer {
#Autowired
Queue queue;
#Autowired
JmsTemplate jmstemplate;
#RequestMapping(method = RequestMethod.GET, path = "/test3/{message}")
public String test3(#PathVariable String message) {
jmstemplate.convertAndSend(queue, message);
return "teste3" + message;
}
}
application.properties
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
server.port=8081
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.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-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
</dependencies>
</project>
This is a screenshot of application starting without starting JMS
Please use below code for jmsTemplate(...) method.
#Bean
public JmsTemplate jmsTemplate() {
return new JmsTemplate(new ActiveMQConnectionFactory("vm://localhost"));
}
I have tested and it is working, let me know if you need sample code.
Also, no need to install ActiveMQ in local when you are using a starter.
Output
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-09-16 12:39:15.477 INFO 14111 --- [ main] c.e.activeissue.ActiveIssueApplication : Starting ActiveIssueApplication on kode12-B250M-D3H with PID 14111 (/home/yprajapati/Downloads/active-issue/target/classes started by yprajapati in /home/yprajapati/Downloads/active-issue)
2019-09-16 12:39:15.493 INFO 14111 --- [ main] c.e.activeissue.ActiveIssueApplication : No active profile set, falling back to default profiles: default
2019-09-16 12:39:16.895 INFO 14111 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-09-16 12:39:16.919 INFO 14111 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-16 12:39:16.919 INFO 14111 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-09-16 12:39:16.991 INFO 14111 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-16 12:39:16.991 INFO 14111 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1407 ms
2019-09-16 12:39:17.204 INFO 14111 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-16 12:39:17.440 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : Using Persistence Adapter: MemoryPersistenceAdapter
2019-09-16 12:39:17.505 INFO 14111 --- [ JMX connector] o.a.a.broker.jmx.ManagementContext : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
2019-09-16 12:39:17.574 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.15.9 (localhost, ID:kode12-B250M-D3H-39191-1568617757456-0:1) is starting
2019-09-16 12:39:17.577 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.15.9 (localhost, ID:kode12-B250M-D3H-39191-1568617757456-0:1) started
2019-09-16 12:39:17.577 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : For help or more information please see: http://activemq.apache.org
2019-09-16 12:39:17.594 INFO 14111 --- [ main] o.a.activemq.broker.TransportConnector : Connector vm://localhost started
2019-09-16 12:39:17.734 INFO 14111 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2019-09-16 12:39:17.737 INFO 14111 --- [ main] c.e.activeissue.ActiveIssueApplication : Started ActiveIssueApplication in 2.872 seconds (JVM running for 3.326)

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)

SpringBoot App fails to start when packaged as a jar

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

Resources