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

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!

Related

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'
}
}
}

Kotlin Gradle build is not running

I have a Spring Boot application backed with Kotlin as the language, and Gradle as the build system. So basically I'm trying to build a fat jar out of the application source and dependencies, which can be run using Java command line tool.
Gradle build script:
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: "kotlin-spring"
apply plugin: 'org.springframework.boot'
group 'myapp'
version '1.0'
buildscript {
ext.kotlin_version = '1.2.21' // Required for Kotlin integration
ext.spring_boot_version = '1.5.4.RELEASE'
repositories {
jcenter()
mavenCentral()
}
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#kotlin-spring-compiler-plugin
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
jar {
zip64 true
manifest {
attributes 'Main-Class': 'app.main.ApplicationKt'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile("org.jetbrains.kotlin:kotlin-reflect")
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
compile 'org.springframework.boot:spring-boot-starter-web'
compile group: 'org.apache.camel', name: 'camel-spring-boot-starter', version: '2.20.2'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.0.0.RELEASE'
compile group: 'org.apache.camel', name: 'camel-quartz2', version: '2.20.2'
compile group: 'org.apache.camel', name: 'camel-http4', version: '2.20.2'
compile group: 'org.apache.camel', name: 'camel-docker', version: '2.20.2'
compile group: 'org.apache.camel', name: 'camel-aws', version: '2.20.2'
compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0'
compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
compile group: 'joda-time', name: 'joda-time', version: '2.9.9'
compile group: 'net.gpedro.integrations.slack', name: 'slack-webhook', version: '1.4.0'
compile group: 'org.json', name: 'json', version: '20180130'
compile group: 'org.jfree', name: 'jfreechart', version: '1.5.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
If I run the project using gradle command then it runs fine. But when I build the jar and try ti run it complains with the below error:-
Error: Could not find or load main class app.main.ApplicationKt
Application.kt:-
#SpringBootApplication
#ImportResource("classpath*:camel-context.xml")
#ComponentScan("app")
class Application
fun main(args:Array<String>){
SpringApplication.run(Application::class.java, *args)
}
Not sure where exactly I'm doing anything wrong.
In Application.kt, you do not have a package declaration. From the documentation:
All the contents (such as classes and functions) of the source file are contained by the package declared. So, in the example above, the full name of baz() is foo.bar.baz, and the full name of Goo is foo.bar.Goo.
If the package is not specified, the contents of such a file belong to "default" package that has no name.
You can look into the build/classes directory to inspect what packages the classes were compiled into.
To fix this issue, add package app.main to the top of the Application.kt file.
for some reason I encountered the same error but my package was declared. I copied the package deleted the line and pasted, saved, reloaded the project and the application ran. I don´t have a logical explanation for this, but that is how I solved this error.

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 !!

Gradle dependencies for Magnolia not found

I'm trying to create a new project with Magnolia and the Gradle dependencies are not found.
Tried this
https://mvnrepository.com/artifact/info.magnolia.blossom/magnolia-module-blossom
Gradle build returns
Could not find info.magnolia.blossom:magnolia-module-blossom:3.1.3.
The gradle file content:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
maven {
url "http://mvnrepository.com/artifact/org.hibernate/hibernate-search-orm"
url "https://mvnrepository.com/artifact/info.magnolia.blossom/magnolia-module-blossom/3.1.3"
url "https://repo.spring.io/libs-milestone"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'test.app'
version = '1.0.0'
}
springBoot {
mainClass = 'com.test.app.Application'
executable = true
}
bootRun {
addResources = true
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-configuration-processor')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-redis')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.boot:spring-boot-starter-security')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-websocket')
compile('org.springframework.session:spring-session:1.2.2.RELEASE')
compile group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.1.0.Final'
compile group: 'com.ryantenney.metrics', name: 'metrics-spring', version: '3.1.3'
compile group: 'io.dropwizard.metrics', name: 'metrics-annotation', version: '3.1.2'
compile group: 'io.dropwizard.metrics', name: 'metrics-graphite', version: '3.1.2'
compile group: 'io.dropwizard.metrics', name: 'metrics-core', version: '3.1.2'
compile group: 'io.dropwizard.metrics', name: 'metrics-jvm', version: '3.1.2'
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
compile group: 'commons-validator', name: 'commons-validator', version: '1.5.1'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.5.0'
compile group: 'org.springframework.security', name: 'spring-security-taglibs', version: '4.1.3.RELEASE'
//https://mvnrepository.com/artifact/org.springframework.security/spring-security-messaging
compile group: 'org.springframework.security', name: 'spring-security-messaging', version: '4.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.3.6.RELEASE'
// Magnolia
compile group: 'info.magnolia', name: 'magnolia-core', version: '5.5'
compile group: 'info.magnolia.blossom', name: 'magnolia-module-blossom', version: '3.1.3'
compile group: 'jstl', name: 'jstl', version: '1.2'
compile('org.ocpsoft.prettytime:prettytime:4.0.1.Final')
runtime('mysql:mysql-connector-java')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
Are there other repositories I can use?
Best Regards,
Razvan
I see two issues you might have
First you added the additional repositories to the repositories block inside the buildscript block. Those are only used for the dependencies of the build script itself like the spring plugin.
What you want is to add at least the blossom repository to the second repositories block where you define the repositories for the dependencies of your application.
The other issue I see is the referenced repositories might be wrong. First only use one url per maven block and the URL might not point to correct maven repositories. Try something like the following:
buildscript {...}
repositories {
mavenCentral()
maven {
url "https://nexus.magnolia-cms.com/content/groups/public/"
}
maven {
url "https://repo.spring.io/libs-milestone"
}
}
Hope that helps.

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