I am creating an annotation driven Spring MVC application using Intellij 2016 and Gradle. My project structure looks like this:
I deliberately copied the persistence.xml into the folder src/main/java/META-INF/persistence.xml and src/main/resources/META-INF/persistence.xml, but when executing the Gradle bootRun task, I get the following error:
11:18:40: Executing external task 'bootRun'...
:compileJava
:processResources
:classes
:findMainClass
:bootRun
11:18:52.960 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named ogm-jpa-tutorial
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at my.app.main.Application.main(Application.java:27)
:bootRun FAILED
It seems that the bootRun tasks is not able to pick up the persistence.xml from the classpath.
Does anyone know whats behind that error and has a fix?
EDIT for javaguy, missing init of EntityManager:
/*
Content of the class my.app.main.Application
*/
package my.app.main;
import my.app.controllers.GreetingController;
import my.app.model.Greeting;
import org.hibernate.validator.internal.util.logging.Log;
import org.hibernate.validator.internal.util.logging.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.TransactionManager;
#SpringBootApplication
#ComponentScan({"my.app.*"})
public class Application {
private static final Log logger = LoggerFactory.make();
public static void main(String[] args) {
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ogm-jpa-tutorial");
SpringApplication.run(Application.class, args);
}
}
EDIT for Asterisk Ninja missing persistence.xml:
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="ogm-jpa-tutorial" transaction-type="JTA">
<!-- Use the Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<!-- Here you will pick which NoSQL technology to use, and configure it;
in this example we start a local in-memory Infinispan node. -->
<property name="hibernate.ogm.datastore.provider" value="infinispan"/>
</properties>
</persistence-unit>
</persistence>
EDIT, missing build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.hibernate.ogm:hibernate-ogm-bom:5.0.2.Final")
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'org.jboss.narayana.jta', name: 'narayana-jta', version: '5.3.5.Final'
compile group: 'org.hibernate', name: 'hibernate-annotations', version: '3.5.6-Final'
testCompile("junit:junit")
}
I solved my problem by adapting the build.gradle file in the following fashion:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.hibernate.ogm:hibernate-ogm-bom:5.0.2.Final")
compile group: 'org.hibernate.ogm', name: 'hibernate-ogm-infinispan', version: '5.0.2.Final'
compile group: 'org.jboss.spec.javax.transaction', name: 'jboss-transaction-api_1.2_spec', version: '1.0.0.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
compile group: 'org.jboss.narayana.jta', name: 'narayana-jta', version: '5.3.5.Final'
compile group: 'org.jboss', name: 'jboss-transaction-spi', version: '7.5.0.Final'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
testCompile("junit:junit")
}
Comment on that:
It seems that the persistence.xml was picked up correctly, but the
EntitiyManager could not initialize the <provider>HibernateOgmPersistence correctly
therefore the following changes were done:
added some dependencies for the EntitiyManager specific for the
MongoDB in-memory instance
Related
I have a Spring Boot (2.1.7) (Gradle project) that I want to deploy to Google App Engine.
I am able to successfully deploy the app (using the documentation found here) but when visiting the app url it returns a 404 Not Found screen:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Not Found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Not Found</h1>
</body></html>
Here's what my build.gradle file looks like:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.1.0'
classpath 'org.akhikhl.gretty:gretty:+'
}
}
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.google.cloud.tools.appengine'
group = 'com.company'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.slf4j', module: 'jul-to-slf4j'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
providedCompile 'com.google.appengine:appengine:+'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'jetty9' // What App Engine Flexible uses
}
appengine {
deploy {
version = "3"
projectId = "apprealtest"
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
Here is what my {projectRoot}/src/main/appengine/app.yaml file looks like:
runtime: java
env: flex
runtime_config: # Optional
jdk: openjdk8
handlers:
- url: /.*
script: this field is required, but ignored
manual_scaling:
instances: 1
This is what my {projectRoot}/src/main/webapp/WEB-INF/appengine-web.xml file looks like:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java8</runtime>
<threadsafe>true</threadsafe>
</appengine-web-app>
This is what the {projectRoot}/src/main/java/com/company/hello/HelloApplication.java looks like:
package com.company.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
This is what the {projectRoot}/src/main/java/com/company/hello/HelloController.java looks like:
package com.company.hello;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HelloController {
#GetMapping("/")
public String get() {
return System.currentTimeMillis() + "";
}
#GetMapping("/greeting")
public String getGreeting() {
return "Greetings!";
}
}
I'm making the call to https://apprealtest.appspot.com and https://apprealtest.appspot.com/greeting.
What am I doing wrong?
To deploy it in GAE Standard you can download this official SpringBoot for App Engine Standard sample.
The instructions are for maven but to do it with Gradle you can simply add this build.gradle file:
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.+' // Latest 1.x.x release
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository (if needed)
}
mavenCentral()
jcenter()
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
apply plugin: 'maven-publish'
dependencies {
compile 'com.google.appengine:appengine-api-1.0-sdk:+' // Latest App Engine Api's
compile 'org.springframework.boot:spring-boot-starter-web:2.1.1.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test:2.1.1.RELEASE'
providedCompile 'org.slf4j:jul-to-slf4j:1.7.25'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.slf4j', module: 'jul-to-slf4j'
}
group = 'com.google.appengine.demos'
version = '0.0.1-SNAPSHOT'
description = 'springboot-appengine-standard'
sourceCompatibility = '1.8'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
And you can deploy it with gradle appengineDeploy.
I tested it myself and it worked. If you want to do it in GAE Flexible the corresponding sample would be this one which also has instructions for Maven so you would have to do the necessary migration to Gradle.
As I have not found a complete example of spring boot with the Gradle build tool.
Added a complete example with updated spring boot version 2.2.3 and AppEngine Gradle plugin 2.2.0.
buildscript {
repositories {
mavenCentral()
maven{
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0'
}
}
plugins {
id 'java'
id 'war'
id 'org.springframework.boot' version '2.2.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.slf4j', module: 'jul-to-slf4j'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compile "com.google.appengine:appengine-api-1.0-sdk:+"
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
providedCompile "com.google.appengine:appengine-api-stubs:+"
providedCompile "com.google.appengine:appengine-testing:+"
providedCompile 'org.slf4j:jul-to-slf4j:1.7.25'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.10.3'
}
apply plugin: "com.google.cloud.tools.appengine"
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
jvmFlags = ['-Ddatastore.backing_store=../../src/main/webapp/WEB-
INF/appengine-generated/local_db.bin', '-Dappengine.fullscan.seconds=5']
port = 8812 // default
}
deploy { // deploy configuration\
stopPreviousVersion = false // default - stop the current version
promote = false // default - & make this the current version
version = 'pr'
projectId = ''
}
}
This repo has a complete example and the test case for its controller. hope it would help.
I'm working on my new project. But when I try to build it, gradle return the error:
error: package org.springramework.transaction does not exist
import org.springframework.transaction.PlatformTransactionManager;
and
error: package org.springramework.orm.hibernate5 does not exist
import org.springframework.orm.hibernate5.HibernateTransactionManager;
Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
def tomcatVersion = '9.0.22'
dependencies {
testImplementation 'junit:junit:4.12'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:8.5.2",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion},"
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.4'
}
tomcat {
httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol'
ajpProtocol = 'org.apache.coyote.ajp.AjpNio2Protocol'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.tomcat:tomcat-dbcp:9.0.22'
implementation 'org.postgresql:postgresql:42.2.6'
implementation 'org.springframework:spring-context:5.1.8.RELEASE'
implementation 'org.springframework:spring-webmvc:5.1.8.RELEASE'
implementation 'org.springframework:spring-orm:5.1.8.RELEASE'
implementation 'org.springframework:spring-tx:5.1.8.RELEASE'
implementation 'org.hibernate:hibernate-core:5.4.1.Final'
}
There is no error about spring context imports.
I know, this is very strange, but in folder
~/.gradle/caches/modules-2/files-2.1/org.springframework there are both spring-orm and spring-tx folder with jars.
What am I doing wrong?
I am trying to build fat jar, but the jar is giving me error. I have built fat jar before with javaFx 11 and java 11. Now I am using Java 8 and Spring I am doing it with intellij from File>Project Structure>Artifacts, there I choose ProjectRoot main module and then also add my resources directory content and I build the jar.
[main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.boo t.enableautoconfiguration' in any property source
21:31:42.635
[main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:450)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:160)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:96)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:386)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:828)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:563)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.tick42.QuicksilverApplication.main(QuicksilverApplication.java:13)
My project is:
>ProjectRoot
>src
>main
>resources
>java
>com
>projectId
>restaurant
RestaurantApplication.class
In restaurant folder are all my config and project classes.
My gradle build is at the project root:
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
group = 'com.projectId'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-security")
testCompile('org.springframework.boot:spring-boot-starter-test')
compile group: 'org.springframework.security', name: 'spring-security-jwt', version: '1.0.2.RELEASE'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.6.0'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.5.2'
compile group: 'org.springframework', name: 'spring-jdbc', version: '5.0.8.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.3.5.Final'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
compile group: 'com.googlecode.log4jdbc', name: 'log4jdbc', version: '1.2'
compile "org.springframework.boot:spring-boot-configuration-processor"
compile 'org.passay:passay:1.3.1'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.kohsuke', name: 'github-api', version: '1.93'
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
check.dependsOn jacocoTestReport
settings.gradle:
rootProject.name = 'server-side'
My RestaurantAplication.class is was in my restaurant folder, but I read somewhere that it should be above my package with my classes, so I moved it to the projectId folder, but it didn't work.
My main:
#SpringBootApplication
#EnableScheduling
#EnableConfigurationProperties
public class RestaurantApplication {
public static void main(String[] args) {
SpringApplication.run(RestaurantApplication.class, args);
}
}
Edit: in the jars's spring.factories in the META-INF folder there is only one line:
org.springframework.beans.BeanInfoFactory=org.springframework.beans.ExtendedBeanInfoFactory
I tried adding them to the file also adding some of the ones listed in the error and also my config files:
org.springframework.beans.BeanInfoFactory=org.springframework.beans.ExtendedBeanInfoFactory
org.springframework.boot.autoconfigure.AutoConfigurationImportSelector
org.springframework.context.annotation.ConfigurationClassParser
com.projectId.restaurant.config.AppConfig
com.projectId.restaurant.config.PasswordEncoderConfig
com.projectId.restaurant.config.ScheduleConfig
com.projectId.restaurant.config.Scheduler
com.projectId.restaurant.config.SecurityConfig
But even then the lines in the error still exist for the exact configurations I have added:
...
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:160)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:96)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:386)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:828)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:563)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
...
I'm a neophyte to Spring Boot, and I wanted to change my default logger to log4j2, since it has a higher throughput rate than logback.
Here's my Gradle script. As you can see, I am using Spring Boot 2.0.3, and to disable the default logger I used exclude module(logback and spring boot starter logger) after Spring Boot Web. I am compiling log4j at the bottom of my script.
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
ext {
vaadinVersion = '8.4.1'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('com.vaadin:vaadin-spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
testCompile('org.springframework.security:spring-security-test')
testCompile 'junit:junit:4.12'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// https://mvnrepository.com/artifact/com.h2database/h2
//compile group: 'com.h2database', name: 'h2', version: '1.0.60'
testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'
}
dependencyManagement {
imports {
mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
}
}
This is my Spring Boot application.
package app.clothapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ClothappApplication {
public static void main(String[] args) {
SpringApplication.run(ClothappApplication.class, args);
}
}
However, when I run my Spring Boot application, it provides me with an AbstractMethodError. I've read some other SO questions, and apparently some class has inappropriately changed since it was last compiled. Could anyone provide some help?
Exception in thread "main" java.lang.AbstractMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
at app.clothapp.ClothappApplication.main(ClothappApplication.java:10)
Thank you.
There will be more than one transitive dependency on spring-boot-starter-logging. For example:
spring-boot-starter-security depends on spring-boot-starter
spring-boot-starter depends on spring-boot-starter-logging
You can run gradle dependencies to confirm.
In order to exlcude a dependency from everywhere, use:
configurations {
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Spring suggest including the dependency on spring-boot-starter and then excluding the logger from there, something like:
compile('org.springframework.boot:spring-boot-starter') {
exclude module: "spring-boot-starter-logging"
}
But I have found that not all Spring dependencies are so well behaved, so the above sometimes fails when there are explicit dependencies on Spring logging elsewhere.
I'm a neophyte to Spring Boot, and I wanted to change my default logger to log4j2, since it has a higher throughput rate than logback.
Here's my Gradle script. As you can see, I am using Spring Boot 2.0.3, and to disable the default logger I used exclude module(logback and spring boot starter logger) after Spring Boot Web. I am compiling log4j at the bottom of my script.
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
ext {
vaadinVersion = '8.4.1'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('com.vaadin:vaadin-spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
testCompile('org.springframework.security:spring-security-test')
testCompile 'junit:junit:4.12'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// https://mvnrepository.com/artifact/com.h2database/h2
//compile group: 'com.h2database', name: 'h2', version: '1.0.60'
testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'
}
dependencyManagement {
imports {
mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
}
}
This is my Spring Boot application.
package app.clothapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ClothappApplication {
public static void main(String[] args) {
SpringApplication.run(ClothappApplication.class, args);
}
}
However, when I run my Spring Boot application, it provides me with an AbstractMethodError. I've read some other SO questions, and apparently some class has inappropriately changed since it was last compiled. Could anyone provide some help?
Exception in thread "main" java.lang.AbstractMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
at app.clothapp.ClothappApplication.main(ClothappApplication.java:10)
Thank you.
There will be more than one transitive dependency on spring-boot-starter-logging. For example:
spring-boot-starter-security depends on spring-boot-starter
spring-boot-starter depends on spring-boot-starter-logging
You can run gradle dependencies to confirm.
In order to exlcude a dependency from everywhere, use:
configurations {
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Spring suggest including the dependency on spring-boot-starter and then excluding the logger from there, something like:
compile('org.springframework.boot:spring-boot-starter') {
exclude module: "spring-boot-starter-logging"
}
But I have found that not all Spring dependencies are so well behaved, so the above sometimes fails when there are explicit dependencies on Spring logging elsewhere.