Problem with Jaeger, logback and Sleuth working together - spring-boot

I was developing a Spring Boot application in which the loging is done by logback and Jaeger is integrated for instrumentation.
Myservice.java
#SpringBootApplication
public class Myservice{
public static void main(String[] args) {
SpringApplication.run(Myservice.class, args);
}
#Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.build();
}
#Bean
public io.opentracing.Tracer jaegerTracer() {
Builder builder = new Builder("Myservice",
new RemoteReporter(new HttpSender(http://192.168.1.20:14268/api/traces), 10,
65000, new Metrics(new StatsFactoryImpl(new NullStatsReporter()))),
new ConstSampler(true))
.registerInjector(Builtin.HTTP_HEADERS, new B3TextMapCodec())
.registerExtractor(Builtin.HTTP_HEADERS, new B3TextMapCodec());
return builder.build();
}
}
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration >
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="springAppName"
source="spring.application.name" />
<appender name="consoleAppender"
class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
Minimum logging level to be presented in the console logs
<level>INFO</level>
</filter>
<encoder
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<pattern>
<pattern>
{
"service": "${springAppName:-}",
"trace": "%X{X-B3-TraceId:-}",
"span": "%X{X-B3-SpanId:-}"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="consoleAppender" />
</root>
</configuration>
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- JPA Data Dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Oracle driver Dependency -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<!-- Opentracing with Jaeger Dependency -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-starter</artifactId>
<version>0.1.4</version>
</dependency>
<dependency>
<groupId>com.uber.jaeger</groupId>
<artifactId>jaeger-core</artifactId>
<version>0.24.0</version>
</dependency>
<dependency>
<groupId>com.uber.jaeger</groupId>
<artifactId>jaeger-b3</artifactId>
<version>0.24.0</version>
</dependency>
<!-- Logback Dependency -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.10</version>
</dependency>
The Jeager is properly connected to server and its getting the traces. The problem is with the logback logs. The traceId and spanId are not getting printed in the logs.
{"service" : "Myservice", "trace": "", "span":""}
But I myself found a solution for that. I added Spring Cloud Sleuth with my Spring Boot application.
<!-- spring-cloud-sleuth dependency -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
Now all the trace information was available in the logback log. But the problem is that Jaeger stopped registering traces to Jaeger server.
I tried Zipkin instead of Jaeger, but the same thing happened. What's wrong with my application? Is something wrong with the dependencies?

You're using Camden release train with boot 2.0 and Sleuth 2.0. That's completely incompatible. Please generate a project from start.spring.io from scratch, please don't put any versions manually for spring cloud projects, and please try again. Try using Finchley release train instead of Camden

Related

Spring boot application not working properly in tomcat server

I have created a small project in spring boot and spring security. It is running perfectly in spring tool suite. And I have created the war file using maven install and deployed to tomcat 9 and trying to run the project. It's opening the login page with out applying the CSS. I have entered the user name and password and submitted. After submitting it's giving HTTP Status 404 – Not Found error. Please help me what went wrong here.
Here is 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 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.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>org.home.ledger</groupId>
<artifactId>HomeLedger</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>HomeLedger</name>
<description>HomeLedger</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-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.2.6.RELEASE</version><!-- $NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</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>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version><!--$NO-MVN-MAN-VER$ -->
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl-api -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.2.6.RELEASE</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId>
<version>2.2.6.RELEASE</version>$NO-MVN-MAN-VER$ </dependency> -->
<!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-core -->
<!-- <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-core</artifactId>
<version>2.2.2.RELEASE</version>$NO-MVN-MAN-VER$ </dependency> -->
<!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-jdbc -->
<!-- <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-jdbc</artifactId>
<version>2.2.2.RELEASE</version>$NO-MVN-MAN-VER$ </dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here my application main class package org.home.ledger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
#SpringBootApplication
public class HomeLedgerApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(HomeLedgerApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(HomeLedgerApplication.class);
}
}
Because the context path in Tomcat is generate based on the WAR file name you must use c:url in your JSP files that URL rewriting is happening:
Read more here https://www.tutorialspoint.com/jsp/jstl_core_url_tag.htm
That way the path independent from the URL it self.

Spring boot log4j2 properties Configuring

Am trying to configuring Log4j2 to log my all logger in an external file so I using spring boot log4j2
i also use Log4J4 Maven Dependencies
i checked so many website they also duing same but don't know what i missing here please help
thanks
Pom.xml file
<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>eta</groupId>
<artifactId>eta_gtc_core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>eta-core-domain-api</module>
<module>eta-core-dao-api</module>
<module>eta-core-dao-impl</module>
<module>eta-core-web</module>
<module>eta-core-domain-impl</module>
<module>eta-core-services-api</module>
<module>eta-core-services-impl</module>
<module>
../../../../../GIT_CLONE_MAT_JAVA_23_JULY/Eta-int-mat-java/SourceCode/JavaSourceCode/eta-common-util
</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Dalston.SR2</spring-cloud.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Application.properties File.
server.port=8080
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
logging.config=src/main/resources/log4j2.properties
log4j2.properties
name=PropertiesConfig
property.filename = logs
appenders = console, file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=D:/core_log/eta_core_web.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
loggers=file
logger.file.name=com.gtc.eta.core.rest
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
logger.file.additivity = false
log4j.appender.console.immediateFlush=true
Spring boot Start Class
import org.springframework.boot.SpringApplication;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
#EnableDiscoveryClient
#SpringBootApplication
public class CoreStart {
private static final Logger LOGGER = LogManager.getLogger(CoreStart.class);
public static void main(String[] args) {
SpringApplication.run(CoreStart.class, args);
LOGGER.info("Info level log message");
LOGGER.debug("Debug level log message");
LOGGER.error("Error level log message");
}
}
Error Code
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/LoggerContext;Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:176)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadDefaults(Log4J2LoggingSystem.java:159)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:84)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:59)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:148)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:303)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:175)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:98)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:64)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.gtc.eta.core.CoreStart.main(CoreStart.java:28)
... 5 more
Measure 1: used this exclusion instead:
<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>
Measure 2: use log4j2.xml instead of log4j2.properties, and put it in src/main/resources
I simplified your project to the following and log4j2 is working as expected:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</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-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This pom configuration
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
is enough to inherit all libs needed to use log4j2.
If you want to use async logging, you have also to specify this one:
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${lmax.disruptor.version}</version>
</dependency>
It is not necessary to specify on application.properties log4j2 property file path if you respect the name convention (log4j2.xml or log4j2-spring.xml). I'd rather use the xml instead the properties file due to a clearer and more readable configuration file. This could be an example using appender to external file and rotate:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %c{1.} - %msg%n"
/>
</Console>
<RollingFile name="RollingFile"
fileName="./logs/logs.log"
filePattern="./logs/$${date:yyyy-MM}/logs-%d{dd-MM-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="100 MB" />
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<AsyncLogger name="your.main.package" level="info" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" />
</AsyncLogger>
<Root level="info" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>
Please note that if you don't want to use async loggers, you have to replace the xml tag AsyncLogger with Logger.
Another error found in your code is in the logger api usage. You should always use the bridge logger to guarantee right maintenance (or full change) of core logging library.
You should then use the slf4j api (already present in your classpath thanks to spring starter dependency).
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Logger logger = LoggerFactory.getLogger(getClass());

Spring Boot Apache Camel Application Not Servicing Requests When in a Container

I have an Spring Boot + Apache Camel Application with the following dependencies listed in the POM file as follows.
<properties>
<fuse-version>fuse-000112-redhat-3</fuse-version>
<camel-version>2.21.0.${fuse-version}</camel-version>
<cxf-version>3.2.7</cxf-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-shiro</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-security-cors</artifactId>
<version>${cxf-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</dependencies>
in
Now I have the following Routes Defined in the camel-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:ctx="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<camelContext trace="false" id="paymentRestCC" allowUseOriginalMessage="true"
xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="properties"
location="classpath:application.properties"/>
<threadPoolProfile id="bigPool" defaultProfile="true"
poolSize="10" maxPoolSize="{{rest.thread.max.pool.size}}"
maxQueueSize="{{rest.thread.max.queue.size}}" allowCoreThreadTimeOut="false"
rejectedPolicy="CallerRuns"/>
<route id="RESTPaymentRoute">
<from
uri="cxfrs:bean:restPaymentService?resourceClass=com.interswitchng.techquest.payment.service.rest.consumer.resources.PaymentRestRequestResource&continuationTimeout={{continuation.timeout}}"/>
<bean ref="restUtil" method="setRequestStartTime"/>
<threads executorServiceRef="bigPool" callerRunsWhenRejected="true">
<bean ref="restUtil" method="printRequestTimeInQueue"/>
<bean ref="restUtil" method="getGenerateTransIdStartTime"/>
<to uri="bean-tranIdGenerator-async://tranIdGeneratorEndpoint"/>
<bean ref="restUtil" method="printGenerateTransIdEndTime"/>
<!-- <throttle> -->
<!-- <constant>40</constant> -->
<to uri="direct-vm:paymentV1Rest"/>
<!-- </throttle> -->
</threads>
</route>
</beans>
I start the application with the following code
#SpringBootApplication
#EnableAutoConfiguration()
public class PaymentServiceRestApplication {
private static ClassPathXmlApplicationContext applicationContext;
public static void main(final String[] args) throws Exception {
applicationContext = new ClassPathXmlApplicationContext("camel-context.xml");
applicationContext.start();
SpringContextHolder.setStaticApplicationContext(applicationContext);
((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR);
}
}
The application starts up properly and it services requests normally. Now the problem arises when I package this application with docker. My docker file is as follows
FROM java:8
LABEL maintainer="babajide.apata#interswitchgroup.com"
ENV http_proxy 'http://x.x.x.x:6060/'
ENV https_proxy 'http://x.x.x.x:6060/'
ENV NO_PROXY 'localhost,127.0.0.1,0.0.0.0,192.168.10.0/24,example.com'
RUN apt-get update && apt-get install -y \
telnet
#Change OS time zone
RUN mv -f /etc/localtime /etc/localtime.bak
RUN ln -s /usr/share/zoneinfo/Africa/Lagos /etc/localtime
ADD payment-service-rest/target/service.jar.jar /opt/p-rest/service.jar
WORKDIR /opt/p-rest
EXPOSE 19080
CMD cat /etc/hosts; java -jar payment-service-rest-4.x.team5-dev.jar;
The container starts up properly but surprisingly enough when i try to access the service through the exposed port from outside the container, I can see from the logs that the requests no longer gets to the app. I can telnet from the host into the container using the exposed port successfully but the requests do not get to the app completely behoves me.

Error when deploying a Spring Boot Websocket/STOMP application on WebLogic 12.2.1

I am creating a Spring Boot REST API that leverages WebSockets/STOMP to send messages to an Angular front end using SockJS. I have gone through great lengths to get the application to deploy in WebLogic 12.2.1C with out using a web.xml. I seem to be close but am having an issue with the Spring Boot Web Socket implementation I am using. I would like to use Spring Boot's implementation and not WebLogics. When I attempt to deploy the war file in WebLogic, I get the following error:
<Could not load user defined filter in web.xml: weblogic.websocket.tyrus.TyrusServletFilter.
java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to org.glassfish.tyrus.server.TyrusServerContainer
at weblogic.websocket.tyrus.TyrusServletFilter.init(TyrusServletFilter.java:76)
at weblogic.servlet.internal.FilterManager$FilterInitAction.run(FilterManager.java:400)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:196)
at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
at weblogic.servlet.internal.FilterManager.initFilter(FilterManager.java:130)
at weblogic.servlet.internal.FilterManager.loadFilter(FilterManager.java:92)
at weblogic.servlet.internal.FilterManager.preloadFilters(FilterManager.java:72)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1917)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3063)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1830)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:875)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
Below is my pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.version>4.2.3.RELEASE</spring.version>
<log4j.version>2.4.1</log4j.version>
<apacheds.server.jndi.version>1.5.5</apacheds.server.jndi.version>
<dao.hibernate.version>1.2.0</dao.hibernate.version>
<commons.lang3.version>3.3.2</commons.lang3.version>
<oracle.version>11.2.0</oracle.version>
<hibernate.core.version>4.3.8.Final</hibernate.core.version>
<hibernate.jpa.version>1.0.0.Final</hibernate.jpa.version>
<httpclient.version>4.5.1</httpclient.version>
<guava.version>19.0</guava.version>
<spring.context.support.version>4.1.7.RELEASE</spring.context.support.version>
<swagger.version>2.4.0</swagger.version>
<surefire.junit47.version>2.18.1</surefire.junit47.version>
<rest-assured.version>2.8.0</rest-assured.version>
<hibernate.validator.version>5.1.3.Final</hibernate.validator.version>
<jacoco.version>0.7.5.201505241946</jacoco.version>
<tomcat.version>8.0.30</tomcat.version>
<powermock.version>1.6.4</powermock.version>
<spring.boot.legacy.version>1.0.1.RELEASE</spring.boot.legacy.version>
<tomcat-jndi-scope>provided</tomcat-jndi-scope>
<commons.io.version>2.4</commons.io.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>${tomcat-jndi-scope}</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>${tomcat.version}</version>
<scope>${tomcat-jndi-scope}</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>${spring.boot.legacy.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-jndi</artifactId>
<version>${apacheds.server.jndi.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<!-- -->
<dependency>
<groupId>com.googlecode.genericdao</groupId>
<artifactId>dao-hibernate</artifactId>
<version>${dao.hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
<!-- ORACLE database driver MUST BE INSTALLED MANUALLY TO MAVEN, SEE README -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.version}</version>
</dependency>
<!-- hibernate-->
<!-- HIBERNATE -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.core.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<optional>true</optional>
<version>${hibernate.jpa.version}</version>
</dependency>
<!-- /HIBERNATE-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- h2 test db -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.context.support.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
</dependencies>
Below is my weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.2.1</wls:weblogic-version>
<wls:context-root>app</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.joda.*</wls:package-name>
<wls:package-name>com.google.common.*</wls:package-name>
<wls:package-name>javax.websocket.*</wls:package-name>
<wls:package-name>javax.websocket.server.*</wls:package-name>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
Below is my entry point to the Spring Boot Web Application
#SpringBootApplication
#Import({
WebAppConfig.class,
CacheConfig.class,
SwaggerConfig.class,
HibernateOracleConfig.class
})
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(Application.class);
}
#Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
// <some context configuration>
ServletRegistration.Dynamic spring = container.addServlet("Spring", new DispatcherServlet(context));
// <some servlet configuration>
// Here, set desired context class using 'contextClass' parameter.
spring.setInitParameter("contextClass", context.getClass().getName());
container.addListener(new ContextLoaderListener(context));
}
}
Please let me know if any more information is needed. I have little experience with WebLogic so am not sure how to proceed, any help or suggestions would definitely be appreciated.
I have changed the maven dependencies to the following...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<scope>provided</scope>
</dependency>
It still works as a Spring Boot application using mvn spring-boot:run, I will let you know if I get any errors when I deploy on WebLogic.
The application was able to deploy successfully but now I have the following error.
2016-04-14 16:16:10,304 [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR o.s.boot.SpringApplication - Error handling failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined
Have you guys seen this issue before?

Spring deployment in jboss error

I just wanted to add spring framework to my project, But when i try to deploy my war file in jboss 6.1.0 Final, it gives a error. I get following error,
11:01:46,556 INFO [STDOUT] ERROR: org.springframework.web.context.ContextLoader - Context initializ
ation failed
11:01:46,557 INFO [STDOUT] org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'com.tapgift.merchant.integration.spring.DaoFactoryPostProcessor#0' defined in class
path resource [config/dao-defs.xml]: Cannot resolve reference to bean 'DAOFactory' while setting bea
n property 'daoFactory'; nested exception is org.springframework.beans.factory.BeanCreationException
: Error creating bean with name 'DAOFactory' defined in class path resource [config/dao-defs.xml]: I
nvocation of init method failed; nested exception is java.lang.NullPointerException
This is dao-def.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- All DAO bean definitions goes here -->
<bean id="DAOFactory"
class="com.tapgift.merchant.integration.db.dao.jdbc.JdbcDaoFactoryImpl" />
<bean class="com.tapgift.merchant.integration.spring.DaoFactoryPostProcessor">
<property name="daoFactory" ref="DAOFactory" />
</bean>
<bean id="merchantDao"
class="com.tapgift.merchant.integration.db.dao.jdbc.JdbcMerchantDao">
<property name="dataSource" ref="dataSource" />
<property name="queryFactory" ref="QueryFactory" />
</bean>
</beans>
This is application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="com.tapgift.merchant" />
<import resource="classpath:config/spring-integration.xml" />
<import resource="classpath:config/dao-defs.xml" />
<import resource="classpath:config/query-defs.xml" />
<import resource="classpath:config/spring-support.xml" />
</beans>
Finally this is web.xml
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/application-context.xml
/WEB-INF/spring/root-context.xml</param-value>
</context-param>
oops, almost missed 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tapgift</groupId>
<artifactId>merchant</artifactId>
<name>merchant-server</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.7</java-version>
<org.springframework-version>3.1.0.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.9</org.aspectj-version>
<org.slf4j-version>1.5.10</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<scope>compile</scope>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSON view resolver -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<!-- Test -->
<!-- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I can see all the files compiled and assembled to the war file. Appreciate, if a spring guru can point me the reason for this deployment error.
Edit: Added DaoFactoryImpl
package com.tapgift.merchant.integration.db.dao.jdbc;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.tapgift.merchant.integration.db.dao.BaseDao;
import com.tapgift.merchant.integration.db.dao.DaoFactory;
import com.tapgift.merchant.integration.db.dao.EntityBaseDao;
/**
* Class <code>CaseServiceImpl</code> is an implementation of the <tt>DaoFactory</tt> interface.
*/
public class JdbcDaoFactoryImpl implements DaoFactory, InitializingBean, ApplicationContextAware
{
private ApplicationContext m_appCtx;
private Map<String, EntityBaseDao<?>> m_daoMap = new HashMap<String, EntityBaseDao<?>>();
/**
* {#inheritDoc}.
*/
#Override
#SuppressWarnings("rawtypes")
public void afterPropertiesSet() throws Exception
{
Map<String, BaseDao> beanMap = m_appCtx.getBeansOfType(BaseDao.class);
for (final BaseDao dao : beanMap.values())
{
m_daoMap.put(((EntityBaseDao) dao).getEntityType().getName(), (EntityBaseDao) dao);
}
}
/**
* {#inheritDoc}.
*/
#Override
public BaseDao getDao(String name)
{
return this.m_daoMap.get(name);
}
/**
* {#inheritDoc}.
*/
#Override
public <T> T getEntityDao(Class<T> clazz)
{
String entityName = ((Class) ((ParameterizedType) clazz.getGenericInterfaces()[0]).getActualTypeArguments()[0])
.getSimpleName().toUpperCase();
return clazz.cast(this.m_daoMap.get(entityName));
}
/**
* Set method for m_appCtx
*/
#Override
public void setApplicationContext(ApplicationContext appCtx) throws BeansException
{
this.m_appCtx = appCtx;
}
}
Update 2
The problem seems to be creating the JdbbcDaoFactoryimpl instance, When i removed the
<bean id="DAOFactory" class="com.tapgift.merchant.integration.db.dao.jdbc.JdbcDaoFactoryImpl" /> with its dependencies, i can deploy it without any problem. I checked the war file and all spring jars are belongs to same version. Need a help desperately.
Issue:
Cannot resolve reference to bean 'DAOFactory' while setting bean
property 'daoFactory';
Cause:
Error creating bean with name 'DAOFactory' defined in class path
resource [config/dao-defs.xml]: Invocation of init method failed;
nested exception is java.lang.NullPointerException
Spring not able to create object of DAOFactory i.e. JdbcDaoFactoryImpl as it came across NullPointerException while initializing object.
Add some relevant code which will help to figure out exact cause.
Update:
Looks like following line is causing the issue
Map<String, BaseDao> beanMap = m_appCtx.getBeansOfType(BaseDao.class);
Spring not able to find bean of type BaseDao. Make sure you have defined a bean of type BaseDao
Never mind, i was able to fix it, Slightly related to what Ajinkya showed.
Problem was m_daoMap.put(((EntityBaseDao) dao).getEntityType().getName() on this code of JdbcDaoFactoryImpl. ((EntityBaseDao) dao).getEntityType() was not returning any value but null. I forgot to override / remove particular method of actual dao implementation class. Once i removed that method, i was able to deploy it without facing any problem.
Thank you for your support anyway.

Resources