Spring Graphql path not found on Docker Container - spring

Hi There
Everything is working without any problem when application is running on IntelliJ IDEA. Mutation is working fine Query is working fine there is no problem at all. But when application is working on docker container I can't access GraphQL path. Spring throws an HTTP "404 not found" exception when an application is working on docker container. I literally did not get it what is the problem. Someone could you help me about that? What is the problem?
Note: Other applications are working fine with POSTMAN except GraphQL application with this docker-compose file. Swagger UI is not seeming on browser. It is also thrown an HTTP 404 Not Found Exception when it is working with docker container Whitelabel Error Page
Error on Docker Container Request port:8093
{
"timestamp": "2023-02-01T19:28:13.384+00:00",
"status": 404,
"error": "Not Found",
"path": "/api/v1/graphql"
}
Browser picture
docker-compose.yaml browser screenshot
localhost browser screenshot
build.gradle file
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.9-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'com.google.protobuf' version '0.8.18'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
def grpcVersion = '1.51.0'
def protobufVersion = '3.19.2'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-graphql'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework:spring-webflux'
testImplementation 'org.springframework.graphql:spring-graphql-test'
//GRAPHQL
implementation 'org.springframework.boot:spring-boot-starter-graphql'
testImplementation 'org.springframework.graphql:spring-graphql-test'
testImplementation 'org.springframework:spring-webflux'
//GRPC
implementation "io.grpc:grpc-netty:${grpcVersion}"
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
implementation 'net.devh:grpc-server-spring-boot-starter:2.14.0.RELEASE'
// Log4j
implementation 'log4j:log4j:1.2.17'
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protobufVersion}" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
}
generateProtoTasks {
all()*.plugins { grpc {} }
}
}
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
tasks.named('test') {
useJUnitPlatform()
}
application.properties
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:postgresql://localhost:5434/userDb
spring.datasource.username=user
spring.datasource.password=123456
spring.graphql.graphiql.enabled=true
spring.graphql.graphiql.path=/graphiql
grpc.server.port=9093
spring.graphql.path=/api/v1/graphql
Dockerfile
FROM eclipse-temurin:17-jdk-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
docker-compose.yml
version: '3.8'
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: rabbitmq
restart: always
ports:
- "5672:5672"
- "15672:15672"
user_db:
image: postgres
container_name: user_db
read_only: true
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=123456
- POSTGRES_DB=userDb
expose:
- "5434"
ports:
- "5434:5434"
tmpfs:
- /tmp
- /run
- /run/postgresql
volumes:
- postgres-user-db-volume:/var/lib/postgresql/data
command: -p 5434
myapp.service:
image: 'myapp.service'
container_name: myapp.service
build:
context: .
dockerfile: Dockerfile
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://user_db:5434/userDb
- SPRING_DATASOURCE_USERNAME=user
- SPRING_DATASOURCE_PASSWORD=123456
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
- SPRING_JPA_HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQLDialect
- SPRING_GRAPHQL_GRAPHIQL_ENABLED=true
- SPRING_GRAPHQL_GRAPHIQL_PATH=/graphiql
- GRPC_SERVER_PORT=9093
- SPRING_GRAPHQL_PATH=/api/v1/graphql
ports:
- "8093:8080"
depends_on:
- user_db
volumes:
postgres-user-db-volume:

Related

Cloud client config application do not get properties from Config Server Spring boot

I have a web application and I want to use Server Configuration from Spring Boot.
Both applications are located on localhost machine. I have made first two applications from scratch and they worked together, but when i use the client that has many dependencies in it (not just the cloud-config and web dependency) it is not working anymore. How do I know? I have a variable in properties file in server and i try to use it in my client with #Value("${atena}")
and error appears java.lang.IllegalArgumentException: Could not resolve placeholder 'atena' in value "${atena}".
The following image is my server config application.
The main class from server has the following annotation #EnableConfigServer
In atena-config.yml I have only the variable name:
atena: 'Hellllloooooo'
bootstrap.yml content
server:
port: 9000
spring:
profiles:
active: native
and build.gradle dependencies:
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I am sure the server it is correct, something is wrong with my client.
--------------------> Client side
I have a restcontroller:
#RestController
#RequestMapping("/songs")
public class SongController {
#Value("${atena}")
String variable;
#GetMapping(value="/check-from")
public String viewVariable(){
return variable;
}
}
in which I am trying to get the variable from server config.
bootstrap.yml from client
spring:
application:
name: atena-config
cloud:
config:
uri: http://localhost:9000
And lastly the build.gradle from client:
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
implementation 'org.springframework.boot:spring-boot-starter'
implementation('org.apache.tomcat:tomcat-jdbc:9.0.10')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation('org.mybatis:mybatis:3.4.6')
implementation('org.mybatis:mybatis-spring:1.3.2')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.cloud:spring-cloud-starter-config')
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I really don't know what happen, I am pretty sure that these dependencies are the problem, but I have not figured out which one, i can not exclude any of them, because I am using them in project.
Never mind. I have fixed it. Indeed the problem was from my dependencies, my gradle.build was with problem. I have created a new project with spring initializer having all the dependencies and copied the new gradle.build from there and now is it working.
This is the new build.gradle from client
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', 'Greenwich.RELEASE')
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

Liquibase changelog not running in spring boot

I´m trying to run a springboot api and configure the database using liquibase.
The problem here is I followed all steps described in several tutorial but the changelog is never executed.
The code:
Gradle config:
group = 'com.strixtools'
version = '0.0.1-SNAPSHOT'
description = """Strix Tools"""
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.1.RELEASE"
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.20.1"
}
}
group = 'strixtools'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.palantir.docker'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
configurations.all {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile ('org.springframework.boot:spring-boot-starter:2.1.1.RELEASE')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'2.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'2.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version:'2.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version:'2.1.1.RELEASE'
compile group: 'org.springframework.security.oauth.boot', name: 'spring-security-oauth2-autoconfigure', version: '2.1.1.RELEASE'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4'
compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.9.0'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version:'2.6.5'
compile group: 'org.liquibase', name: 'liquibase-core'
compile group: 'com.h2database', name: 'h2', version:'1.4.196'
runtime group: 'org.postgresql', name: 'postgresql'
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'2.1.1.RELEASE')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version:'2.1.1.RELEASE'
}
task stage {
dependsOn build
}
task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}
docker {
name "${project.group}/${bootJar.baseName}"
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
aplication.yml
strix-api:
host: https://aaa.com
client: asdasdasfasdf
secret: afadsfsdaf
user: afdadsfsadf
pass: afadsfsdafsdaf
---
spring:
profiles: local
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
liquibase:
change-log: classpath:db/changelog-master.xml
enabled: true
drop-first: true
jpa:
hibernate:
ddl-auto: none
show-sql: true
h2:
console:
enabled: true
and my SpringAplication class
#SpringBootApplication
public class StrixToolsApplication {
public static void main(String[] args) {
SpringApplication.run(StrixToolsApplication.class, args);
}
//TODO: we should move this to another side
#Bean(name = "messageSource")
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource messageBundle = new ReloadableResourceBundleMessageSource();
messageBundle.setBasename("classpath:messages/messages");
messageBundle.setDefaultEncoding("UTF-8");
return messageBundle;
}
#Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}
The problem is liquibase is never executing. If I change the changelog name to anthing else it doesn't even throws an error.
Thanks for your help
Regards
In my case the problem was that I had a dependency declared for the gradle plugin, like so
liquibaseRuntime("org.liquibase:liquibase-core:3.8.1")
but not for liquibase at runtime, like so
runtimeOnly("org.liquibase:liquibase-core:3.8.1")
Maybe you are missing the right version of liquibase. Try with 2.0.1.
Here you have a small sample: (you can refactor the notation that you are using for versions and groups).
apply plugin: 'liquibase'
plugins {
id 'io.spring.dependency-management' version '1.0.5.RELEASE'
id 'org.liquibase.gradle' version '2.0.1'
}
ependencies {
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-validation')
implementation('org.liquibase:liquibase-core')
runtime 'mysql:mysql-connector-java'
liquibaseRuntime group: 'org.liquibase', name: 'liquibase-core', version: liquibaseCoreVersion
liquibaseRuntime group: 'org.liquibase', name: 'liquibase-groovy-dsl', version: liquibaseGroovyDslVersion
liquibaseRuntime 'mysql:mysql-connector-java'
}
liquibase {
activities {
main {
changeLogFile 'src/main/resources/db/liquibase-changelog.xml'
url 'jdbc:mysql://' + System.env.DATABASE_HOST + ':' + System.env.DATABASE_PORT + '/' + System.env.DATABASE_NAME + '?useSSL=false'
username System.env.DATABASE_USER
password System.env.DATABASE_PASSWORD
driver 'com.mysql.jdbc.Driver'
}
}
}

Configure application.properties in spring boot for public url in keycloak

I'm developing spring boot application (v 2.1.0) with keycloak to secure app (v 4.5.0).
I already configured keycloak security in gradle and application.properties.
However keycloak returns unauthorized (401 Error) even for urls which are not added to security constraints.
Gradle and application.properties file are provided following
Gradle
buildscript {
ext.kotlin_version = '1.3.11' // Required for Kotlin integration
ext.spring_boot_version = '2.1.0.RELEASE'
ext.keycloak_version = '4.5.0.Final'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
}
}
apply plugin: 'kotlin' // Required for Kotlin integration
apply plugin: "kotlin-spring" // https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
jcenter()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile group: 'org.hibernate', name: 'hibernate-envers', version: '5.1.0.Final'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Required for Kotlin integration
compile("org.jetbrains.kotlin:kotlin-reflect")
compile "org.springframework.boot:spring-boot-starter-web"
// compile 'org.springframework.boot:spring-boot-starter-security'
//KeyCloak
compile group: 'org.keycloak', name: 'keycloak-spring-boot-starter', version: '4.7.0.Final'
compile group: 'org.keycloak', name: 'keycloak-spring-boot-adapter', version: '4.7.0.Final'
compile "org.keycloak:keycloak-admin-client:$keycloak_version"
//RestEasy
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client
compile group: 'org.jboss.resteasy', name: 'resteasy-client', version: '3.6.2.Final'
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.6.2.Final'
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider
compile group: 'org.jboss.resteasy', name: 'resteasy-jackson2-provider', version: '3.6.2.Final'
// //Oauth2
// // https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2
// compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.4.RELEASE'
// https://mvnrepository.com/artifact/org.springframework/spring-jdbc
compile group: 'org.springframework', name: 'spring-jdbc', version: '5.1.0.RELEASE'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
compile group: 'org.postgresql', name: 'postgresql', version: '9.3-1100-jdbc41'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Application.properties
#Server
server.port = 8090
# Database
spring.jpa.database=postgresql
#spring.datasource.platform
spring.jpa.show-sql=false
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/dbname
spring.datasource.username=postgres
spring.datasource.password=123
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
# new
keycloak.realm = realm
keycloak.auth-server-url = http://localhost:8080/auth
keycloak.ssl-required = external
keycloak.resource = client_id
keycloak.credentials.secret = client_secret
keycloak.realm-key=public_key
keycloak.security-constraints[0].auth-roles[0]=USER
keycloak.security-constraints[0].security-collections[0].patterns[0]=/user/*
keycloak.security-constraints[0].security-collections[0].patterns[1]=/createStudent
keycloak.security-constraints[0].auth-roles[1]=admin
keycloak.security-constraints[0].security-collections[1].patterns[0]=/createStudent2
keycloak.security-constraints[0].security-collections[1].patterns[1]=/createRole
keycloak.security-constraints[0].security-collections[1].patterns[2]=/roles
keycloak.security-constraints[0].security-collections[1].patterns[3]=/assignRole
keycloak.security-constraints[0].security-collections[1].patterns[4]=/users
I want login and main page of the app to be public
/login and /home
Thanks in advance!

Execute Cucumber Integration Tests with Spring Boot server running from Gradle plugin on Jenkins or any other CI server

I have a spring boot micro-services project built with Gradle.
I want to execute my cucumber integration tests on Jenkins or CI server just after code check-in. The build job on CI server gets triggered automatically after every code check-in. This job calls my gradle build.
I am able to execute the cucumber test cases as normal JUnit test case from my STS or eclipse and the embedded tomcat server gets started and after the cucumber test cases get executed on it, the server is stopped.
This is exactly what I want through gradle build:
How the cucumber integration tests get executed on a running spring boot embedded server by gradle.build ??
Current behavior is: when the gradle.build is called on CI server then the cucumber integration tests are just getting called with no target spring boot server.
Expected behavior: After gradle.build is called on CI server, the cucumber tests should get executed on the running spring boot embedded server and should get stop by itself after the cucumber test cases are executed.
NOTE: I have created a special cucumber-test profile for it in the project and have its own configuration file
My gradle.build looks like:
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
manifest {
attributes 'Main-Class': 'com.pa.omas.Main'
}
baseName = 'omas'
version = ''
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "http://smartbearsoftware.com/repository/maven2" }
}
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 testCompile
integrationTestRuntime.extendsFrom testRuntime
cucumberRuntime {
extendsFrom testRuntime
}
}
task copyScripts(type: Copy) {
from("scripts")
into("build/libs")
}
task copyReports(type: Copy) {
from("reports")
into("build/libs/reports")
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}
check.dependsOn integrationTest
integrationTest.mustRunAfter test
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
}
bootRun {
args = ["--spring.profiles.active=cucumber-test"]
}
task cucumber(){
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-p', 'pretty', '--monochrome', '-p', 'html:reports/cucumber/cucumber-html-reports', '-p', 'junit:reports/cucumber-junit/cucumber-junit-report.xml',
'-p', 'html:reports/cucumber', '--glue', 'src/integration-test/java/com/pa/omas/cucumber', 'src/integration-test/resources']
}
copyReports
}
}
build {
dependsOn copyScripts
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-stream-kafka')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-web')
compile('ch.qos.logback:logback-classic')
compile('org.mariadb.jdbc:mariadb-java-client:1.5.4')
compile('org.hibernate:hibernate-java8')
compile 'com.puppycrawl.tools:checkstyle:8.3'
compile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.11.0'
compile group: 'net.masterthought', name: 'maven-cucumber-reporting', version: '3.11.0'
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.6.3'
compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
testCompile('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
integrationTestCompile('com.h2database:h2')
integrationTestCompile('org.springframework.boot:spring-boot-starter-test')
integrationTestCompile 'info.cukes:cucumber-java:1.2.5'
integrationTestCompile 'junit:junit:4.12'
integrationTestCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-html', version: '0.2.6'
integrationTestCompile group: 'info.cukes', name: 'cucumber-jvm-deps', version: '1.0.5'
integrationTestCompile group: 'info.cukes', name: 'gherkin', version: '2.12.2'
integrationTestCompile group: 'io.cucumber', name: 'gherkin', version: '5.0.0'
integrationTestCompile group: 'info.cukes', name: 'cucumber-java8', version: '1.2.5'
integrationTestCompile group: 'org.webjars.npm', name: 'gherkin', version: '4.1.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR3"
}
}
My project structure looks like:
StepsDefinitionAnnotations
CucumberTest
Thanks very much !!
So finally, I found the solution to this issue.
The cucumber cli main class was unable to find the testRuntime in which the stepsDefinition file was located. Therefore, it was simply calling the cucumber test cases but not executing them.
All I did is included the sourceSets for main & test in the gradle file, linke below:
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
}
test {
java {
srcDirs = ["src/test/"]
}
}
}
And it worked fine for me.
Thanks Anyways. Hope this will help others as well !!

Slf4j with log4j2 not working Spring boot 1.4.3.RELEASE

I was using Spring boot 1.3.6.RELEASE and log4j2.yml as below:
Configuration:
status: info
Properties:
Property:
name: log-path
value: "/dvl-log/pol/apps/logs/api"
Appenders:
Console:
- name: Console
target: SYSTEM_OUT
PatternLayout:
Pattern: "%d{HH:mm:ss.SSS} %-5level %logger{1} - %msg%n"
Loggers:
Root:
level: info
AppenderRef:
- ref: Console
Logger:
- name: com.company.api
level: trace
additivity: false
AppenderRef:
- ref: Console
level: trace
The logging with below code was working perfectly.
#Slf4j
public class LogExample{
public void logMethods(String className,String methodName){
log.trace("{} >> {}", className, methodName);
}
}
But when I upgraded to Spring Boot 1.4.3.RELEASE, the logger is not working.
My new build.gradle after upgrading to 1.4.3 is (just a version change)
version '1.0'
// dependencies for command line
buildscript {
ext {
springBootVersion = '1.4.3.RELEASE'
dependencyManagementVersion = '0.5.2.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
}
}
apply plugin: "io.spring.dependency-management"
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'idea'
// JDK 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
jcenter()
}
ext {
springCloudVersion = 'Brixton.SR4'
springBootVersion = '1.4.3.RELEASE'
swaggerVersion = '2.4.0'
jodaTimeVersion = '2.9.4'
jacksonJodaVersion = '2.5.1'
junitVersion = '4.12'
springWsTestVersion = '2.2.3.RELEASE'
lombokVersion = '1.16.10'
jsonPathVersion = '2.2.0'
ehcacheVersion = '3.2.0'
javaxCacheVersion = '1.0.0'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
}
}
sourceSets {
test {
java {
srcDir 'src/test/unit/java'
}
resources {
srcDir 'src/test/unit/resources'
}
}
}
dependencies {
/* core libraries */
compile('org.springframework.cloud:spring-cloud-starter-config') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-hateoas"){
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
compile 'org.springframework.ws:spring-ws-core'
// logging
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')
compile('com.fasterxml.jackson.core:jackson-databind')
// embedded server
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
// https://mvnrepository.com/artifact/org.projectlombok/lombok-maven
compile "org.projectlombok:lombok:${lombokVersion}"
// https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path
// A Java DSL for reading JSON documents
compile "com.jayway.jsonpath:json-path:${jsonPathVersion}"
/* plugins */
/* test libraries */
// unit
testCompile "junit:junit:${junitVersion}"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "org.springframework.ws:spring-ws-test:${springWsTestVersion}"
}
war {
archiveName = "${project.name}.war"
}
What thing I'm missing here? TIA
I want to add more details:
there are log4j-api:2.6.2, log4j-core:2.6.2 and log4j-slf4j-impl:2.2.6 on classpath after upgrading to Spring Boot 1.4.3. The thing is appender is not working for trace level because I am getting log for info or above level.
I resolved this problem by moving log4j2.yml directly into resource directory.
Earlier, with Spring Boot 1.3.6, I had put log4j2.yml under resources/logging directory with configuration.yml as
logging:
config: classpath:logging/log4j2.yml
I don't know why it didn't work for 1.4.3.RELEASE.

Resources