Issue
In my application there is two ContextConfigLocation in web.xml.
<!-- ============================================================
Entitlement Analytics Spring Dispatcher Servlet
============================================================ -->
<servlet>
<servlet-name>analytics</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>com.javaetmoi.core.spring.JBoss5XmlWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/analytics-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>analytics</servlet-name>
<url-pattern>/analytics/c/*</url-pattern>
</servlet-mapping>
<!-- ============================================================
ELM Spring MVC DispatcherServlet
============================================================ -->
<servlet>
<servlet-name>elmoadmin</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>com.javaetmoi.core.spring.JBoss5XmlWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/elmoadmin-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
For elmoadmin-sevlet the bean is
<bean class="com.lehman.elmo.admin.mvc.config.SwaggerConfig"/>
<bean class="com.lehman.elmo.analytics.config.MongoConfig"/>
<bean class="com.lehman.elmo.analytics.config.ConfigFromYAML"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
<property name="writeConcern">
<util:constant static-field="com.mongodb.WriteConcern.SAFE" />
</property>
</bean>
For servlet analytics-context
<context:annotation-config/>
<context:component-scan base-package="com.lehman.elmo.analytics.*,com.lehman.elmo.list.*"/>
<context:component-scan base-package="com.lehman.pp.*"/>
<context:component-scan base-package="com.lehman.elmo.audit.service" />
<mvc:annotation-driven/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
<!-- <property name="writeConcern">-->
<!-- <util:constant static-field="com.mongodb.WriteConcern.SAFE"/>-->
<!-- </property>-->
</bean>
ConfigFromYAML is in config package.
Now when I see the bean for the analytics-context I am getting the value but for elmo-adminh servlet the config gives as null. This happened after I upgraded from spring 4.3.9 to 5.2.26.
Config Class
package com.lehman.elmo.analytics.config;
import java.util.List;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource(value="classpath:ea-application.yaml",factory = YamlPropertySourceFactory.class)
@ConfigurationProperties(prefix = "application")
@Data
public class ConfigFromYAML {
private Elmo hostedElmo;
private Elmo ctElmo;
private Smtp smtp;
private Notification notification;
private Report report;
private MongoConfig mongo;
private ConfigReport configReport;
@Data
public static class Elmo {
private String server;
private int port;
}
@Data
public static class Smtp {
private String server;
private int port;
private String sender;
private List<String> ccList;
private String devTo;
}
@Data
public static class Notification {
private String subject;
private String emailTemplate;
}
@Data
public static class Report {
private String subject;
private String readyTemplate;
private boolean asAttachment;
private List<String> includeInactiveUser;
}
@Data
public static class ConfigReport {
private String subject;
private String readyTemplate;
private boolean asAttachment;
}
@Data
public static class MongoConfig {
private String serverUrl;
private String dbname;
private String username;
private String password;
private String serviceName;
private String configFile;
}
}
In firstcase for analytics-context servlet i get values as
2022-06-09 04:15:52,569|main|INFO |com.lehman.elmo.analytics.config.MongoConfig.log.62| - ++++++++++EAConfig(hostedElmo=abc, ctElmo=abc, smtp=abc, notification=abc, report=abc, mongo=abc, configReport=abc)
for elmoadmin-servlet I get 2022-06-09 04:15:52,569|main|INFO |com.lehman.elmo.analytics.config.MongoConfig.log.62| - ++++++++++EAConfig(hostedElmo=null, ctElmo=null, smtp=null, notification=null, report=null, mongo=null, configReport=null)
the build file
apply plugin: 'war'
defaultTasks 'clean', 'build', 'distUcfClient', 'distElmClient', 'distAutosysJobs'
buildscript {
repositories {
maven { url = 'org-url' }
}
dependencies {
classpath "com.eriwen:gradle-js-plugin:2.14.0"
classpath 'com.eriwen:gradle-css-plugin:2.14.0'
//classpath 'org.sonarqube:org.sonarqube.gradle.plugin:2.7'
}
}
apply plugin: com.eriwen.gradle.js.JsPlugin
apply plugin: 'maven'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
springVersion = "5.2.6.RELEASE"
luceneVersion = "4.0.0-BETA"
jacksonVersion = '2.9.4'
splunkVersion = "1.5.0.0"
libsDir = "libs"
clientSrcDir = "src/client"
log4jVersion = '2.17.1'
}
repositories {
maven { url = 'https://org-url' }
mavenCentral()
}
sourceSets {
main {
java { srcDir "$clientSrcDir/java" }
}
}
dependencies {
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version:'2.2.4.RELEASE'
compile ("org.springframework.boot:spring-boot-starter:2.2.0.RELEASE")
{
exclude group: 'org.apache.logging.log4j'
}
compile "org.springframework:spring-webmvc:$springVersion"
compile 'org.springframework.ws:spring-ws-core:2.2.0.RELEASE'
compile "org.springframework:spring-context-support:$springVersion"
compile "org.springframework:spring-orm:$springVersion"
compile "org.springframework:spring-jms:$springVersion"
compile 'org.springframework.data:spring-data-commons:2.2.5.RELEASE'
compile 'com.alibaba.spring:spring-webmvc-velocity:1.4.3.18.RELEASE'
compile ('org.springframework.data:spring-data-mongodb:2.2.5.RELEASE')
compile "org.springframework.hateoas:spring-hateoas:1.4.0"
compile "org.springframework.plugin:spring-plugin-core:1.1.0.RELEASE"
compile "org.mongodb:mongo-java-driver:3.11.2"
compile "org.apache.activemq:activemq-spring:5.10.0"
compile "org.apache.activemq:activemq-kahadb-store:5.10.0"
compile "org.reflections:reflections:0.9.10"
compile "cglib:cglib-nodep:2.2"
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
compile "org.projectlombok:lombok:1.18.20"
annotationProcessor "org.projectlombok:lombok:1.18.20"
compile 'com.google.guava:guava:18.0'
compile 'org.yaml:snakeyaml:1.25'
compile 'ch.qos.logback:logback-classic:1.2.2'
compile 'ch.qos.logback:logback-core:1.1.7'
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'net.logstash.logback:logstash-logback-encoder:4.9'
compile 'com.oracle:ojdbc6:11.2.0.3.0'
compile "com.mangofactory:swagger-springmvc:0.8.5"
compile "com.javaetmoi.core:javaetmoi-spring4-vfs2-support:1.3.0"
compile "com.bc.WPS:elmo-client:2.6"
compile "ldapjdk:ldapjdk:5.2"
compile "org.apache.lucene:lucene-core:$luceneVersion"
compile "org.apache.lucene:lucene-queries:$luceneVersion"
compile("org.apache.lucene:lucene-test-framework:$luceneVersion") {
exclude group: 'junit'
}
compile "javax.jms:javax.jms-api:2.0.1"
compile "org.apache.lucene:lucene-analyzers-common:$luceneVersion"
compile "org.apache.lucene:lucene-queryparser:$luceneVersion"
compile "com.splunk:splunk:$splunkVersion"
compile("commons-codec:commons-codec:1.10")
compile "com.jayway.jsonpath:json-path:2.4.0"
compile ("com.bc.etg:etg-framework:14.3.7.1"){
exclude group: 'log4j'
}
compile ("com.splunk.logging:splunk-library-javalogging:1.6.1")
{
exclude group: 'org.apache.logging.log4j'
}
/*compile "org.apache.logging.log4j:log4j-api:2.15.0"
compile "org.apache.logging.log4j:log4j-core:2.15.0"*/
compile "com.jayway.jsonpath:json-path:2.4.0"
compile "uk.org.lidalia:sysout-over-slf4j:1.0.2"
compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
compile "org.apache.logging.log4j:log4j-api:$log4jVersion"
compile fileTree("$libsDir")
providedRuntime fileTree(dir: "$libsDir",
include: ["phaseTracker.jar", "jsp-2.0.jar", "servlet.jar", "xalan.jar", "xercesImpl-2.4.0.jar"
, "xml-apis-1.0.b2.jar", "webserviceclient.jar", "jstl.jar", "jstl-1.1.0.jar", "stax-api-1.0-2.jar", "jaxrpc.jar"])
testCompile("junit:junit:4.11") {
exclude module: 'hamcrest-core'
}
testCompile("org.springframework:spring-test:$springVersion")
testCompile("org.mockito:mockito-all:1.10.19")
testCompile("com.lordofthejars:nosqlunit-mongodb:0.8.0")
testCompile 'com.tngtech.java:junit-dataprovider:1.9.3'
}
war {
baseName 'ELM'
from("$buildDir") {
include 'elmo-all.js'
into 'ng-elmo-ui'
}
from("$buildDir") {
include 'elmo-all.min.js'
into 'ng-elmo-ui'
}
from("ng-elmo-ui/app") {
exclude 'elmo-all.js'
into 'ng-elmo-ui'
}
from("$buildDir") {
include 'elmo-list-all.js'
into 'list'
}
from("list/app") {
exclude 'elmo-list-all.js'
into 'list'
}
}
war.dependsOn 'minifyJs'
war.dependsOn 'minifyJsList'
task minifyJsList(type: com.eriwen.gradle.js.tasks.CombineJsTask){
def jsDir = "list/app/scripts"
def compDir = "list/app/components"
source = [
"$jsDir/browser-redirect.js",
"$jsDir/vendor/underscore.js",
"$jsDir/vendor/jquery/jquery-1.12.4.js",
"$jsDir/vendor/jquery/jquery-ui-1.10.3.min.js",
"$jsDir/vendor/angular/1.2.4/angular.min.js",
"$jsDir/vendor/angular/1.2.4/angular-touch.min.js",
"$jsDir/vendor/angular/1.2.4/angular-route.min.js",
"$jsDir/vendor/angular/1.2.4/angular-resource.min.js",
"$jsDir/vendor/angular/1.2.4/angular-animate.min.js",
"$jsDir/vendor/angular/ui-bootstrap-tpls.min.js",
"$jsDir/vendor/ag-grid/ag-grid.js",
"$jsDir/vendor/restangular.min.js",
"$jsDir/vendor/angular-wysiwyg/angular-wysiwyg.js",
"$jsDir/vendor/angular-wysiwyg/bootstrap-colorpicker-module.js",
"$jsDir/vendor/bootstrap/bootstrap.min.js",
"$jsDir/vendor/sweetalert/sweet-alert.min.js",
"$jsDir/vendor/bootstrap/datepicker/bootstrap-datepicker.js",
"$jsDir/vendor/fastclick.min.js",
"$jsDir/vendor/checklist-model.js",
"$jsDir/vendor/moment/moment.min.js",
"$jsDir/ng-list.js"
] + fileTree(dir: compDir, include: '**/*.js')
// better way is to use RequireJS
dest = file("$buildDir/elmo-list-all.js")
}
combineJs {
def jsDir = "ng-elmo-ui/app/scripts"
def compDir = "ng-elmo-ui/app/components"
source = [
"$jsDir/vendor/underscore.js",
"$jsDir/vendor/jquery/jquery-1.10.1.min.js",
"$jsDir/vendor/jquery/jquery-ui-1.10.3.min.js",
"$jsDir/vendor/angular/1.2.4/angular.min.js",
"$jsDir/vendor/angular/1.2.4/angular-touch.min.js",
"$jsDir/vendor/angular/1.2.4/angular-route.min.js",
"$jsDir/vendor/angular/1.2.4/angular-resource.min.js",
"$jsDir/vendor/angular/1.2.4/angular-animate.min.js",
"$jsDir/vendor/angular/ui-bootstrap-tpls.min.js",
"$jsDir/vendor/angular/ng-grid.min.js",
"$jsDir/vendor/angular-ui-grid/ui-grid.js",
"$jsDir/vendor/ag-grid/ag-grid.js",
"$jsDir/vendor/restangular.min.js",
"$jsDir/vendor/bootstrap/bootstrap.min.js",
"$jsDir/vendor/bootstrap/bootstrap-modal-popover.js",
"$jsDir/vendor/sweetalert/sweet-alert.min.js",
"$jsDir/vendor/moment/moment.min.js",
"$jsDir/ng-elmo.js",
"$jsDir/ng-elmo-config.js",
"$jsDir/ng-elmo-route.js"
] + fileTree(dir: compDir, include: '**/*.js')
// better way is to use RequireJS
dest = file("$buildDir/elmo-all.js")
}
minifyJs {
source = combineJs
dest = file("$buildDir/elmo-all.min.js")
sourceMap = file("${buildDir}/elmo-all.sourcemap.json")
closure {
warningLevel = 'QUIET'
compilerOptions.languageIn = 'ECMASCRIPT5_STRICT'
}
}
task compileClient(type: JavaCompile) {
source "$clientSrcDir/java"
destinationDir = file("$buildDir/classes/clientClass")
classpath = sourceSets.main.compileClasspath
}
/**
* UCF Client Build
*/
task ucfClientJar(dependsOn: compileClient, type: Jar) {
from compileClient.destinationDir
exclude 'com/lehman/elmo/**'
baseName 'ucf-client'
}
task ucfClientJavadoc(dependsOn: ucfClientJar, type: Javadoc) {
source "$clientSrcDir/java"
include 'com/lehman/llservices/usergroup/**/*.java'
exclude('**/EtgGroupLDAPProcessor.java'
, '**/EtgGroupValidationDecorator.java'
, '**/LegacyEtgGroupHttpProcessor.java')
destinationDir = file('build/docs/javadoc/ucf-client-docs')
classpath = files(
"$libsDir/commons-codec-1.6.jar",
"$libsDir/etg-framework-7.0.1.jar",
"$libsDir/servlet.jar")
title = '<"![CDATA[<h1>UCF Client API</h1>]]>'
}
task distUcfClient(dependsOn: [ucfClientJar, ucfClientJavadoc], type: Tar) {
baseName 'ucf_client'
from("$buildDir/libs") { include 'ucf-client.jar' }
from("$buildDir/docs/javadoc/ucf-client-docs") { include '**/*' into 'java-docs' }
}
/**
* ELM Client Build
*/
task elmClientJar(dependsOn: compileClient, type: Jar){
from compileClient.destinationDir
exclude 'com/lehman/llservices/**'
baseName 'elm-client'
}
task elmClientJavadoc(type: Javadoc) {
source "$clientSrcDir/java"
include 'com/lehman/elmo/admin/**/*.java'
destinationDir = file("$buildDir/docs/javadoc/elm-client-docs")
classpath = sourceSets.main.compileClasspath
title = '<![CDATA[<h1>ELM Client API</h1>]]>'
}
task distElmClient(dependsOn: [elmClientJar, elmClientJavadoc], type: Tar) {
baseName 'elm_client'
from("$buildDir/libs") { include 'elm-client.jar' }
from("$buildDir/docs/javadoc/elm-client-docs") {
include '**/*'
into 'java-docs'
}
}
/**
* Autosys Jobs
*/
task distAutosysJobs(dependsOn: compileJava, type: Tar) {
baseName 'elmo_autosys_job_app'
from(sourceSets.main.resources.srcDirs) { into 'classes' }
from(compileJava.destinationDir) { into 'classes' }
from(sourceSets.main.resources.srcDirs) {
include('**/*.properties', '*.xml', '*.html')
exclude 'log4j.properties'
into 'config'
}
from("$webAppDirName/WEB-INF") {
include('analytics-context-app.xml', 'analytics-context-autosys.xml')
into 'config'
}
from(configurations.runtime) {
exclude 'webserviceclient.jar'
into 'lib'
}
from('scripts') {
include('syncagent_console.sh', '.SmartDLRefreshProfile', '.syncagentprofile', 'syncagent.sh')
}
from('scripts/scheduled') {
include('*.sh', '*.py', '.elmo_autosys_job_profile*')
}
}
wrapper { gradleVersion = '5.5' }
Solution
Missed the @EnableConfigurationProperties . On adding it worked fine
Answered By - Dipanjan Bhattacharya
Answer Checked By - Senaida (JavaFixing Volunteer)