slf4j LoggerFactory class definition not found with Gradle - maven

I'm trying to build and run a Spark webserver that uses slf4j logging in IntelliJ. It builds fine (also in IntelliJ) on the computer that was used to originally add logging, but not on my machine.
Here's the full build.gradle file (see project(':webserver') for the part that uses the logger:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.avast.gradle:docker-compose-gradle-plugin:0.3.27"
}
}
subprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
apply plugin: "java"
apply plugin: "idea"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "findbugs"
apply plugin: "application"
apply plugin: "com.avast.gradle.docker-compose"
checkstyle {
configFile = "../config/checkstyle/checkstyle.xml" as File
toolVersion = "6.0"
}
}
project(':webserver') {
mainClassName = "org.passport.webserver.WebServer"
dependencies {
compile project(':core')
compile "com.sparkjava:spark-core:2.6.0"
testCompile 'junit:junit:4.12'
compile group: 'org.json', name: 'json', version: '20090211'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':customsUI') {
mainClassName = "org.passport.customsui.CustomsUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':handlerUI') {
mainClassName = "org.passport.handlerui.HandlerUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':core') {
mainClassName = "org.passport.core.PassPortChaincode"
dependencies {
compile 'io.grpc:grpc-all:0.13.2'
compile 'commons-cli:commons-cli:1.3.1'
compile 'org.glassfish:javax.json:1.1.0-M1'
compile files('lib/shim-client-1.0.jar')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
Here's the code that uses the logger:
package org.passport.webserver;
import org.passport.webserver.endpoints.ContainerClaimDao;
import org.passport.webserver.endpoints.PackageClaimDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.path;
import static spark.Spark.post;
/**
* The server matches requests (routs) and calls the appropriate endpoints.
*/
public final class Server {
private static Logger logger = LoggerFactory.getLogger(Server.class);
private static ContainerClaimDao containers = new ContainerClaimDao();
private static PackageClaimDao packages = new PackageClaimDao();
private Server() {
}
/**
* Starts the router.
* #param args run arguments
*/
public static void main(String[] args) {
path("/containers/:container-id", () -> {
before("/*", (q, a) -> logger.info("Received api call: " + q.url() + "."));
post("", (request, response) -> containers.add(request, response));
get("/container-claims", (request, response) -> containers.get(request, response));
get("/package-claims", (request, response) -> packages.get(request, response));
});
}
}
And here's the error I get:
"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\Users\lover\repositories\passport\webserver\build\classes\main;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.passport.webserver.Server
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.passport.webserver.Server.<clinit>(Server.java:18)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
I've looked at several questions on StackOverflow, but none seem to solve the problem:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory - I'm building with gradle, don't think I should have to download/ put some jar in my classpath
ClassNotFoundException: org.slf4j.LoggerFactory - Same as above
NoClassDefFoundError: org/slf4j/Logger - Again jar stuff
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory - I'm not sure whether "fat jars" / ShadowJar apply, and not sure how to modify my build file to use them
NoClassDefFoundError: org/slf4j/LoggerFactory while creating a runnable *.jar with gradle - I've tried refreshing gradle several times, restarting IntelliJ, and even restarting my restarting my computer
Gradle Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory - See below
I've tried the following dependencies:
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
compile 'org.slf4j:slf4j-api:1.7.24' and compile 'org.slf4j:slf4j-simple:1.7.24'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
None of this seems to make a difference. Any ideas?

If you're using Gradle add these 2 lines to your build.gradle dependencies to use Spark 2.6.0
compile "com.sparkjava:spark-core:2.6.0"
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'

I ended up deleting my Gradle cache (.gradle folder) and re-downloading everything, which solved the problem.

Related

Cannot resolve class TableOptions generated by jOOQ

I'm using jOOQ 3.13.0 with Gradle.
Here are some related excerpts from the build.gradle
...
buildscript {
dependencies {
classpath 'org.jooq:jooq-codegen:3.13.3'
classpath 'org.postgresql:postgresql:42.2.5'
}
}
...
dependencies {
compile 'org.jooq:jooq:3.13.3'
}
...
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd') {
jdbc() {
driver('org.postgresql.Driver')
url('jdbc:postgresql://localhost:5432/metrics')
user('postgres')
password('pwd')
}
generator() {
database() {
inputSchema('public')
}
// Watch out for this caveat when using MarkupBuilder with "reserved names"
// - https://github.com/jOOQ/jOOQ/issues/4797
// - http://stackoverflow.com/a/11389034/521799
// - https://groups.google.com/forum/#!topic/jooq-user/wi4S9rRxk4A
generate() {
}
target() {
packageName('metrics.jooq')
directory('src/main/java')
}
}
}
After I run gradle clean build it generates the code successfully but it cannot be compiled because it contains:
import org.jooq.TableOptions;
which cannot be resolved. How can I resolve this. It's very strange that it generates code that cannot be compiled...
I noticed that Gradle has downloaded version 3.11.9 instead of 3.13.3 for some reason.
After that I changed all the jooq related versions to 3.11.9 (also xsd version) in build.gradle and ran the build but got:
Error while reading XML configuration
Here is the end of the stack trace:
...
Caused by: org.jooq.codegen.GeneratorException: Error while reading XML configuration
at org.jooq.codegen.GenerationTool.load(GenerationTool.java:931)
at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:218)
at org.jooq.codegen.GenerationTool$generate.call(Unknown Source)
at build_abyn1owj8gv09akc1mcgpsxr1.run(/media/wd/job/otr/mk/ufos-portal-incubate/solutions/mk-dashboard/build.gradle:56)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
... 104 more
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
at org.jooq.codegen.GenerationTool.load(GenerationTool.java:914)
... 108 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
... 109 more
I tried to resolve it as suggested here
https://github.com/jOOQ/jOOQ/issues/9066
and added to build.gradle
dependencies {
classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '3.0.0-M4'
classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '3.0.0-M4'
classpath group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
...
but without success
I've solved the problem by using the right dependencies
Here is the excerpt from build.gradle
buildscript {
dependencies {
classpath group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1'
classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1'
classpath 'org.jooq:jooq-codegen:3.11.9'
classpath 'org.postgresql:postgresql:42.2.5'
...

Karate Gatling with gradle build is not working [duplicate]

This question already has answers here:
How to run Karate and Gatling with Gradle build system
(2 answers)
Closed 1 year ago.
I am trying to run gatling with karate in gradle build and getting below error,
/smoketests/SmokeTestRunner.java:19: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
^
/smoketests/SmokeTestRunner.java:21: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
^
/smoketests/SmokeTestRunner.java:30: error: cannot find symbol
#RunWith(Karate.class)
^
symbol: class RunWith
/wskadmin/WskAdminRunner.java:19: error: package org.junit does not exist
import org.junit.Test;
^
/wskadmin/WskAdminRunner.java:20: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
^
/wskadmin/WskAdminRunner.java:22: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
and exception as
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGatlingScala'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
For more information,
below is my build.gradle file,
plugins {
id "com.github.lkishalmi.gatling" version "0.7.3"
}
apply plugin: 'java'
apply plugin: 'maven'
group = 'karate-gatling'
version = '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
}
sourceSets {
gatling {
scala.srcDirs = ['src/test/java']
}
test {
java
{
srcDir file('src/test/java')
// exclude '**/*.java'
}
resources
{
srcDir file('src/test/java')
// exclude '**/*.java'
}
}
}
dependencies {
compile group: 'com.jcraft', name: 'jsch', version:'0.1.53'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.10.0'
compile group: 'com.intuit.karate', name: 'karate-netty', version:'0.8.0.1'
testCompile group: 'net.masterthought', name: 'cucumber-reporting', version:'3.8.0'
testCompile group: 'com.intuit.karate', name: 'karate-apache', version:'0.8.0.1'
testCompile group: 'com.intuit.karate', name: 'karate-junit4', version:'0.8.0.1'
testCompile group: 'com.intuit.karate', name: 'karate-gatling', version:'0.8.0.1'
gatling 'com.intuit.karate:karate-gatling:0.8.0.1'
gatling 'com.google.code.gson:gson:2.8.0'
gatling 'org.apache.httpcomponents:httpclient:4.3.2'
gatlingCompile 'org.apache.commons:commons-lang3:3.4'
gatlingRuntime 'cglib:cglib-nodep:3.2.0'
}
gatling {
sourceRoot = 'src/test/java'
toolVersion = '2.3.1'
}
to run my simulation class i am using below command,
./gradlew clean gatlingRun-mypackage.LoadTest
Below is my LoadTest.scala file
class LoadTest extends Simulation {
before{
println("Simulation is about to start!")
}
val createActionTest = scenario("smoke").exec(karateFeature("classpath:path/myfeature.feature"))
setUp(createActionTest.inject(rampUsers(5) over (5 seconds))
).maxDuration(1 minutes).assertions(global.responseTime.mean.lt(1100))
after {
println("Simulation is finished!")
}
}
And below is my runner file
import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
#RunWith(Karate.class)
#CucumberOptions(tags = {"~#ignore","~#driver","~#reliability","~#resiliency","~#concurrent","~#wskfunctions"})
public class SmokeTestRunner {
}
Any help on this is really appriciated
You need to add a testCompile dependency on JUnit, such as:
testCompile 'junit:junit:4.12'
gradle karate karate-gatling junit gradle-gatling-plugin

Gradle Spring Boot Project Cannot Run From IDEA [duplicate]

This question already has answers here:
NoClassDefFoundError after IntelliJ IDEA upgrade
(3 answers)
Closed 5 years ago.
I am struggling to set up the spring boot project that i have imported in intelliJ IDEA 2016 1.4.
Every time i run . I get the below Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.patientConnect.DemoApplication.main(DemoApplication.java:24)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
My gradle settings (linked gradle projects,user gradle wrapper ) all looks good.
package com.Demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public DemoApplication() {
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
build.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE'
classpath 'gradle.plugin.com.jamesward:atom-gradle-plugin:0.0.1'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-parent:1.5.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.security.oauth:spring-security-oauth2'
compile 'org.apache.httpcomponents:httpclient'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.postgresql:postgresql'
compile 'org.springframework.boot:spring-boot-starter-jdbc'
compile 'org.hibernate:hibernate-entitymanager'
}
allprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
import org.gradle.internal.os.OperatingSystem
task devClasses(type: Exec) {
if (OperatingSystem.current().isWindows())
commandLine 'gradlew', '-t', 'classes'
else
commandLine './gradlew', '-t', 'classes'
}
task devBootRun(type: Exec) {
if (OperatingSystem.current().isWindows())
commandLine 'gradlew', 'bootRun'
else
commandLine './gradlew', 'bootRun' //, '--debug-jvm'
}
import java.util.concurrent.*
task dev() << {
def devClassesFuture = Executors.newSingleThreadExecutor().submit({ devClasses.execute() } as Callable)
def devBootRunFuture = Executors.newSingleThreadExecutor().submit({ devBootRun.execute() } as Callable)
devClassesFuture?.get()
devBootRunFuture?.get()
}
task stage {
dependsOn build
}
Try deleting your SpringBoot dependency on your computer.
It will be located at ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot Assuming you kept your gradle dependencies in the default location.
rm -rf ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot
or to delete all dependencies (Just to be sure if no other dependencies is corrupted)
rm -rf ~/.gradle/caches/modules-2/files-2.1/*
then to re-download
gradle build --refresh-dependencies

Unable to inject properties into a class in Spring boot sub module added as a jar in the war

I have a spring boot project with multiple modules which have to be deployed separately. Want to utilize common modules like model,dao and utilities between the projects.
When I had a single project, I was able to get the mongodb related properties loaded for MongoDBConfiguration class.
But when I have dao as a separate module, on server startup spring complains that it cannot resolve the properties required by MongoDBConfiguration class.
Here is my proj structure:
ExampleProj
dao
common
model
webmodule_x
module_y
module_z
build.gradle
Apart from main build.gradle, i have build.gradle for each module.
My dao module has MongoDBConfiguration class like this:
#Configuration
#PropertySource(value = "classpath:/application.properties")
#EnableMongoRepositories(basePackages="com.abc.xyz.dao.repositories*" )
public class MongoDBConfiguration {
#Value( "${mongo.host:abc12345.abc.com}" ) private String mongoHost;
#Value( "${mongodb.name}" ) private String mongodbName;
....
}
Tried different configurations but have the same problem.
My webmodule_x has spring boot starter class like this:
#PropertySource(value={"classpath:application.properties",
"file:${externalDirectory}/webmodule_x/conf/application.properties"
} ,
ignoreResourceNotFound = false)
#ComponentScan("com.abc.xyz")
#Configuration
#EnableAutoConfiguration
#EnableMongoRepositories(basePackages="com.abc.xyz.dao*" )
#Import(MongoDBConfiguration.class)
public class SpringBootStarter {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(SpringBootStarter.class, args);
}
}
Somehow ${mongodb.name} property is not getting initialized.
This is the error I get:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'mongodb.name' in string value "${mongodb.name}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:801) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:955) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
... 86 common frames omitted
This is my build.gradle in webmodule_x like this:
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'idea'
def tomcat_home='/usr/local/apache-tomcat-7.0.55'
sourceCompatibility = 1.7
buildscript {
repositories {
maven { url "http://mavencentral.it.abc.com:8084/nexus/content/groups/xyz" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
systemProperties = System.properties
}
tasks.withType(Test) {
// get System properties needed for tests
systemProperties['externalDirectory'] =
System.getProperty("externalDirectory", "/opt/app/test")
println 'externalDirectory for tests is ' +
systemProperties['externalDirectory']
}
repositories {
maven { url "http://mavencentral.it.abc.com:8084/nexus/content/groups/xyz" }
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations{
integrationTestCompile.extendsFrom compile, testCompile
integrationTestRuntime.extendsFrom runtime, testRuntime
providedRuntime
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework:spring-webmvc')
compile project(':common')
compile project(':model')
compile project(':dao')
testCompile('junit:junit','org.hamcrest:hamcrest-library','org.mockito:mockito-core')
testCompile('junit:junit','org.hamcrest:hamcrest-library','org.springframework.boot:spring-boot-starter-test',
'org.mockito:mockito-core', 'org.skyscreamer:jsonassert:1.2.3')
integrationTestCompile('junit:junit','org.hamcrest:hamcrest-library','org.springframework.boot:spring-boot-starter-test',
'org.mockito:mockito-core', 'org.skyscreamer:jsonassert:1.2.3')
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
task integrationTest(type: Test) {
description = 'Runs the integration tests.'
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}
// logback(slf4j) commons-logging
[configurations.runtime, configurations.default]*.exclude(module: 'commons-logging')
jar.enabled = true
bootRepackage.enabled = true
My dao build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
sourceCompatibility = 1.7
version = '1.0'
group = 'com.abc.xyz.dao'
version = '0.0.1-SNAPSHOT'
buildscript {
repositories {
maven { url "http://mavencentral.abc.com:8084/nexus/content/groups/xyz" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
configurations{
providedRuntime
}
repositories {
maven { url "http://mavencentral.abc.com:8084/nexus/content/groups/xyz" }
}
dependencies {
compile 'org.springframework.data:spring-data-mongodb'
compile project(':model')
compile 'org.springframework:spring-context'
testCompile('junit:junit','org.hamcrest:hamcrest-library','org.mockito:mockito-core',
'org.mockito:mockito-core', 'org.skyscreamer:jsonassert:1.2.3', 'org.springframework.boot:spring-boot-starter-test',
'org.springframework:spring-webmvc','org.springframework.boot:spring-boot-starter-web', 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.46.4')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
jar.enabled = false
bootRepackage.enabled = false
Googled a lot but no luck yet. I get this error both with bootRun and with war deployment into tomcat.
Please let me know how to load properties before an injected bean in a dendent jar class is initialized.
I'm sure you have already checked this but perhaps your keys in the prop file are incorrect?
From your code, I see mongo.host and then mongodb.name
Perhaps the "db" is not in your props?

WebApplicationInitializer is not launched on jetty+selenium

i am trying to run selenium test on jetty using gradle and my gradle configuration is as follows:
gradle.build:
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
apply plugin: 'findbugs'
//apply from:'http://github.com/breskeby/gradleplugins/raw/master/emmaPlugin/emma.gradle'
apply from: 'emma.gradle'
apply plugin: 'jetty'
sourceCompatibility = 1.7
version = ''
sourceSets {
selenium
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6'
}
}
repositories {
mavenCentral()
mavenRepo url: 'http://repository.primefaces.org'
mavenRepo url: 'http://repository.jboss.org/nexus/content/groups/public'
mavenRepo url: 'http://repository.jboss.org/maven2'
mavenRepo url: 'http://maven.springframework.org/release'
mavenRepo url: 'http://repo1.maven.org/maven2'
mavenRepo url: 'http://git.solutionstream.com/nexus/content/repositories/thirdparty'
}
dependencies {
//JSF
compile group: 'com.sun.faces', name: 'jsf-api', version: '2.1.22'
compile group: 'com.sun.faces', name: 'jsf-impl', version: '2.1.22'
compile 'org.ocpsoft.rewrite:rewrite-servlet:2.0.3.Final'
compile 'org.ocpsoft.rewrite:rewrite-config-prettyfaces:2.0.3.Final'
compile 'javax.el:el-api:2.2'
runtime 'org.glassfish.web:el-impl:2.2'
//Servlet
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
providedCompile group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: '1.0.0.Final'
compile 'taglibs:standard:1.1.2'
compile group: 'org.springframework', name: 'spring-web', version: '3.2.2.RELEASE'
//Omnifaces
compile 'org.omnifaces:omnifaces:1.5'
//Prime Faces
compile group: 'org.primefaces', name: 'primefaces', version: '4.0-SNAPSHOT'
compile 'org.primefaces.themes:bootstrap:1.0.10'
// DB
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.3.1.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version: '3.2.2.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.9'
compile group: 'javax.inject', name: 'javax.inject', version: '1'
compile group: 'javax.enterprise', name: 'cdi-api', version: '1.0-SP4'
compile 'cglib:cglib-nodep:2.2.2'
//Hibernate / JPA
compile 'org.hibernate:hibernate-core:4.1.0.Final'
compile 'org.hibernate:hibernate-entitymanager:4.1.0.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
//JSR-303
compile 'org.hibernate:hibernate-validator:4.3.1.Final'
// Spring Security
compile 'org.springframework.security:spring-security-core:3.1.4.RELEASE'
compile 'org.springframework.security:spring-security-web:3.1.4.RELEASE'
compile 'org.springframework.security:spring-security-config:3.1.4.RELEASE'
//Utility
compile 'com.google.guava:guava:14.0.1'
compile 'commons-lang:commons-lang:2.6'
compile 'org.apache.commons:commons-email:1.3.1'
compile 'com.typesafe:config:1.0.0'
compile 'joda-time:joda-time:2.2'
compile 'org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:1.8.3'
compile 'org.slf4j:slf4j-api:1.7.2'
compile 'org.slf4j:jcl-over-slf4j:1.7.2'
compile 'org.slf4j:slf4j-log4j12:1.7.2'
//Mustache Templates
compile 'com.github.jknack:handlebars:1.0.0'
//Projects
//compile project(":ExtraValidators")
////TESTING DEPENDENCIES
testCompile 'com.googlecode.jmockit:jmockit:1.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'com.h2database:h2:1.3.172'
//Spring Testing
testCompile 'org.springframework:spring-test:3.2.3.RELEASE'
/* Selenium */
seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.33.0'
seleniumCompile 'junit:junit:4.11'
}
task wrapper(type: Wrapper){
gradleVersion = '1.5'
}
eclipse {
classpath {
downloadSources=true
plusConfigurations += configurations.seleniumCompile
}
}
task jettyDaemon(type: org.gradle.api.plugins.jetty.JettyRun) {
daemon = true
}
task selenium(type: Test, dependsOn: jettyDaemon) {
testClassesDir = sourceSets.selenium.output.classesDir
classpath = sourceSets.selenium.runtimeClasspath
}
WebApplicationInitializer:
package com.myapp.web.config;
import javax.faces.application.ProjectStage;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import com.myapp.data.config.SpringConfig;
import com.myapp.data.config.SpringJNDIDataConfig;
import com.myapp.data.config.SpringJNDIJPAConfig;
import com.myapp.data.config.SpringSecurityConfig;
import com.myapp.data.config.SpringWebConfig;
import com.myapp.utils.configuration.ConfigurationUtil;
public class WebappConfig implements WebApplicationInitializer {
protected final Logger logger = LoggerFactory.getLogger(getClass());
#Override
public void onStartup(final ServletContext servletContext) throws ServletException {
if(logger.isDebugEnabled()) {
logger.debug("Starting web context configuration");
}
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
// rootContext.getEnvironment().setActiveProfiles("production");
rootContext.register(SpringConfig.class, SpringSecurityConfig.class, SpringWebConfig.class, SpringJNDIDataConfig.class, SpringJNDIJPAConfig.class);
servletContext.addListener(RequestContextListener.class);
new ContextLoader(rootContext).initWebApplicationContext(servletContext);
addFilters(servletContext, rootContext.getEnvironment());
servletContext.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, ConfigurationUtil.config().getString("jsf.stage"));
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", ConfigurationUtil.config().getString("jsf.refreshPeriod"));
}
private void addFilters(final ServletContext servletContext, final ConfigurableEnvironment configurableEnvironment) {
FilterRegistration.Dynamic securityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain"));
securityFilter.addMappingForUrlPatterns(null, false, "/*");
}
}
please advise how to make WebApplicationInitializer runs when running the selenium test on jetty.
WebApplicationInitializer requires a Servlet 3 container. However, Gradle's Jetty plugin is based on Jetty 6 which supports only Servlet 2.5.
You have a few options:
Configure your application with the web.xml file instead of WebApplicationInitializer
Use a newer Jetty version with Gradle. There are some workarounds in the comments of GRADLE-1956
Use an alternative container like Tomcat (gradle-tomcat-plugin)
Use an alternative plugin like gradle-cargo-plugin or arquillian-gradle-plugin. AFAIK there's a new gradle deployment plugin in the works that should be base on Arquillian.

Resources