Here is my build.gradle
buildscript {
ext {
springBootVersion = '2.0.0.M2'
}
repositories {
mavenCentral()
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-security',
'org.springframework.boot:spring-boot-starter-mail',
'org.springframework.boot:spring-boot-starter-validation',
'org.springframework.boot:spring-boot-starter-webflux',
// support libs
'commons-io:commons-io:2.5',
'commons-codec:commons-codec:1.10',
'org.apache.commons:commons-lang3:3.4',
'org.apache.commons:commons-collections4:4.1',
//validation
'javax.validation:validation-api:1.1.0.Final'
compileOnly 'org.springframework.boot:spring-boot-configuration-processor',
'org.projectlombok:lombok'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
When I tried to run application it fails with java.lang.IllegalStateException: java.lang.NullPointerException
Stacktrace:
java.lang.IllegalStateException: java.lang.NullPointerException
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.stopAndReleaseReactiveWebServer(ReactiveWebServerApplicationContext.java:152) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:52) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
at com.getcredit.bankscraper.Application.main(Application.java:10) [main/:na]
Caused by: java.lang.NullPointerException: null
at org.springframework.boot.web.embedded.netty.NettyWebServer.stop(NettyWebServer.java:113) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.stopAndReleaseReactiveWebServer(ReactiveWebServerApplicationContext.java:148) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
... 7 common frames omitted
Project was generated via start.spring.io site.
After some tests, I've found out my problem. That was an NPE exception in init method of my bean annotated with #PostConstruct. You can reproduce this issue like this:
#Component
class Test {
String str;
#PostConstruct
private void init() {
System.out.println(str.length());
}
}
I don't understand why spring throws so unclear exception.
Related
Can't generate aspectOf() method wih gradle plugin.
My AspectJ config class and some aspect class:
#Aspect
public class SendToAspect {
#Around("execution (public * *(..)) && #annotation(ann)")
public Object execute(final ProceedingJoinPoint point, final SendTo ann) throws Throwable {
return point.proceed();
}
}
#Configuration
#EnableAspectJAutoProxy
public class AspectjConfiguration {
#Bean
public SendToAspect sendToAspect() {
return Aspects.aspectOf(SendToAspect.class);
}
}
My build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id "io.freefair.aspectj.base" version "5.1.0"
}
allprojects {
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
dependencyManagement {
dependencies {
dependency 'org.projectlombok:lombok:1.18.12'
}
}
}
subprojects {
apply plugin: 'java'
group 'com.example'
version '0.0.1-snapshot'
sourceCompatibility = 1.8
dependencies {
compileOnly 'org.projectlombok:lombok'
}
}
configure([project(':my-service')]) {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.freefair.aspectj.base'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework:spring-aspects'
implementation 'org.aspectj:aspectjrt'
}
}
After building and running my springBoot app I get the same error:
error creating bean with name 'sendToAspect' defined in class path resource
[com/example/config/aspectj/AspectjConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.utils.aop.SendToAspect]:
Factory method 'sendToAspect' threw exception; nested exception is org.aspectj.lang.NoAspectBoundException:
Exception while initializing com.restaurantclub.soa.utils.aop.SendToAspect: java.lang.NoSuchMethodException: com.restaurantclub.soa.utils.aop.SendToAspect.aspectOf()
What needs to be done or which plugin should i use to work?
My Gradle version: 5.2.1
Solution - just use 'io.freefair.aspectj.post-compile-weaving' instead io.freefair.aspectj.base
I am creating javafx app with spring boot in background. To do this I used this library: springboot-javafx-support Every time when I start it I get exception "No auto configuration found in META-INF/spring.factories". I have no idea what I am doing wrong. I guess it must be something wrong in my gradle build script.
Below you can find gradle.build file
buildscript {
ext {
springBootVersion = '2.0.1.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'
group = 'pl.opfol.subiekt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
jar {
enabled = true
}
bootJar {
mainClassName = 'pl.opfol.subiekt.util.MainApp'
}
repositories {
mavenCentral()
maven {
url "https://artifact.aspose.com/repo"
}
maven {
url "https://dl.bintray.com/jerady/maven"
}
}
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('com.h2database:h2:1.4.197')
compile('javax.mail:javax.mail-api:1.6.1')
compile('com.sun.mail:javax.mail:1.6.1')
compile('commons-io:commons-io:2.6')
compile('commons-codec:commons-codec:1.11')
compile('org.apache.commons:commons-collections4:4.1')
compile('org.apache.commons:commons-lang3:3.7')
compile('commons-configuration:commons-configuration:1.10')
compile('com.aspose:aspose-words:17.3.0:jdk16')
compile('com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre9')
compile('javax.annotation:javax.annotation-api:1.3.2')
compile('org.controlsfx:controlsfx:9.0.0')
compile('com.itextpdf:itext7-core:7.1.1')
compile('javax.xml.bind:jaxb-api:2.3.0')
compile('com.jfoenix:jfoenix:9.0.0')
compile('de.roskenet:springboot-javafx-support:2.1.6')
compile('de.jensd:fontawesomefx-controls:9.1.2')
compile('de.jensd:fontawesomefx-commons:9.1.2')
compile('de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2')
compile('de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2')
compile('de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2')
compile('de.jensd:fontawesomefx-octicons:4.3.0-9.1.2')
compile('de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2')
compile('de.jensd:fontawesomefx-materialstackicons:2.1-5-9.1.2')
compile('de.jensd:fontawesomefx-icons525:4.2.0-9.1.2')
compile('de.jensd:fontawesomefx-emojione:3.1.1-9.1.2')
compileOnly ('org.hibernate:hibernate-jpamodelgen:5.2.16.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I had same problem, make sure you run it on JRE 1.8.
I am coming from Maven workd and new to Gradle.I have multi-module Gradle product with following modules:
"cdna-common"
'cdna-data-access'
"cdna-api-dto"
"cdna-api-module"
"cdna-request-executor-module"
my root settings.glade looks like this:
rootProject.name = 'cdna-one-platform'
include "cdna-common"
include 'cdna-data-access'
//include "cdna-api-dto" //commented temporary
include "cdna-api-module"
//include "cdna-request-executor-module" //commented temporary
gradle file for module 'cdna-data-access' is :
buildscript {
ext {
springBootVersion = '2.0.0.M6'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
ext['hibernate.version'] = '5.2.11.Final'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.company.cdna'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
baseName = 'cdna-one-data-access'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
a
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('mysql:mysql-connector-java')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.hibernate:hibernate-search-orm')
compile group: 'org.hibernate', name: 'hibernate-search-orm' , version: '5.8.2.Final'
compile group: 'org.apache.lucene', name: 'lucene-analyzers-kuromoji' , version: '5.5.5'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.h2database:h2')
}
Module 'cdna-common' depends on 'cdna-one-data-access' and gradle file looks like :
apply plugin: 'java'
apply plugin: 'eclipse'
group = 'com.company.cdna'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
baseName = 'cdna-one-commons'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile project(':cdna-data-access')
}
When I compile the module 'cdnHowever,cess' using 'gradlew cdna-data-access:build' , it compiles without any error.
However , when I try to compile the module 'cdna-common' using 'gradlew cdna-common:build' , it gives following error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':cdna-common:compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter:.
Searched in the following locations:
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter//spring-boot-starter-.pom
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter//spring-boot-starter-.jar
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter//spring-boot-starter-.pom
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter//spring-boot-starter-.jar
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter//spring-boot-starter-.pom
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter//spring-boot-starter-.jar
Required by:
project :cdna-common > project :cdna-data-access
> Could not find mysql:mysql-connector-java:.
Searched in the following locations:
https://repo1.maven.org/maven2/mysql/mysql-connector-java//mysql-connector-java-.pom
https://repo1.maven.org/maven2/mysql/mysql-connector-java//mysql-connector-java-.jar
https://repo.spring.io/snapshot/mysql/mysql-connector-java//mysql-connector-java-.pom
https://repo.spring.io/snapshot/mysql/mysql-connector-java//mysql-connector-java-.jar
https://repo.spring.io/milestone/mysql/mysql-connector-java//mysql-connector-java-.pom
https://repo.spring.io/milestone/mysql/mysql-connector-java//mysql-connector-java-.jar
Required by:
project :cdna-common > project :cdna-data-access
> Could not find org.springframework.boot:spring-boot-starter-data-jpa:.
Searched in the following locations:
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.pom
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.jar
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.pom
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.jar
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.pom
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.jar
Required by:
project :cdna-common > project :cdna-data-access
Any tips of what I am doing wrong?
When I try to compile/build a Spring Boot project with Spark/Phoenix dependencies, it says there's too many SLF4J's, and when i try to exclude a package, it throws the above error.
How can i get them to work together?
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
//THIS DOESN'T WORK
configurations {
compile.exclude group:'ch.qos.logback'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
/* EXCLUDING HERE ALSO DIDN'T WORK */
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.apache.spark:spark-sql_2.10:1.5.2')
compile('org.apache.spark:spark-core_2.10:1.5.2')
compile('org.apache.phoenix:phoenix-spark:4.7.0-HBase-1.1')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I'm newer using Gradle, I have this file build.gradle:
apply plugin: 'maven'
apply plugin: 'spring-boot'
group = "com.test.sample"
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
classpath 'io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
repositories {
maven {
credentials {
username = nexusUsername
password = nexusPassword
}
url "${nexusUrl}/content/repositories/releases/ex--common/"
mavenCentral()
jcenter()
eventuateMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
}
}
dependencies {
compile "com.test.sample:EX--Common:${exCommonVersion}"
compile "com.test.sample:EX--CommonSwagger:${exCommonSwaggerVersion}"
compile("org.springframework.boot:spring-boot-devtools")
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
compile "io.eventuate.local.java:eventuate-local-java-jdbc:${eventuateLocalVersion}"
compile "io.eventuate.local.java:eventuate-local-java-embedded-cdc-autoconfigure:${eventuateLocalVersion}"
testCompile "junit:junit:4.11"
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
}
I install gradle 3.4.1 in my machine. When I do
gradle build
or
gradle assemble
I get this error:
Failed to apply plugin [class 'io.spring.gradle.dependencymanagement.DependencyManagementPlugin']
Could not create task of type 'DependencyManagementReportTask'.
Would you have any ideas how I can fix that?
This is the stacktrace info:
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':xxx'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:92)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:181)
.....
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'io.spring.dependency-management']
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:155)
at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:112)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:113)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:44)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.java:34)
at org.gradle.api.Script$apply$0.callCurrent(Unknown Source)
at build_cq297at3shymhbbwfq82eq5ag.run(C:\Users\xxx\build.gradle:13)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
... 62 more
Caused by: org.gradle.api.tasks.TaskInstantiationException: Could not create task of type 'DependencyManagementReportTask'.
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:123)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:118)
at org.gradle.util.GUtil.uncheckedCall(GUtil.java:402)
at org.gradle.api.internal.AbstractTask.injectIntoNewInstance(AbstractTask.java:178)
at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:118)
at org.gradle.api.internal.project.taskfactory.TaskFactory.createTask(TaskFactory.java:77)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.createTask(AnnotationProcessingTaskFactory.java:46)
at org.gradle.api.internal.project.taskfactory.DependencyAutoWireTaskFactory.createTask(DependencyAutoWireTaskFactory.java:39)
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:76)
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:111)
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:141)
at org.gradle.api.internal.tasks.DefaultTaskContainer_Decorated.create(Unknown Source)
at org.gradle.api.internal.tasks.DefaultTaskContainer_Decorated$create.call(Unknown Source)
at io.spring.gradle.dependencymanagement.DependencyManagementPlugin.apply(DependencyManagementPlugin.groovy:64)
at io.spring.gradle.dependencymanagement.DependencyManagementPlugin.apply(DependencyManagementPlugin.groovy)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:139)
... 72 more
Caused by: org.gradle.internal.service.UnknownServiceException: No service of type StyledTextOutputFactory available in ProjectScopeServices.
at org.gradle.internal.service.DefaultServiceRegistry.getServiceProvider(DefaultServiceRegistry.java:436)
at org.gradle.internal.service.DefaultServiceRegistry.doGet(DefaultServiceRegistry.java:426)
at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:414)
at org.gradle.api.internal.DependencyInjectingInstantiator.convertParameters(DependencyInjectingInstantiator.java:81)
at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:54)
at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:121)
... 89 more
Best regards