I am writing a test explanation, of which I have done this plenty of times, and I am getting strange behavior. I run the test and then I get:
No username
com.bsb.pr.test.domain.UserException: No username
at app//com.bsb.pr.test.service.UserService.fetchUserById(UserService.kt:21)
at app//com.bsb.pr.test.UserServiceTestNoKSpock.getUserNameById throws exception if username is null(UserServiceTestNoKSpock.kt:23)
at java.base#17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
The follow is the code that is used:
#Service
class SubscriptionService {
fun getSubscriptionByUserId(id: Number): Subscription? {
return Subscription("email#email.com")
}
}
#Service
class UsernameService {
fun getUserNameById(id: Number): Username? = Username("test")
}
Focal Service
#Service
class UserService(
private val usernameService: UsernameService,
private val subscriptionService: SubscriptionService
) {
fun fetchUserById(id: Number): User {
val username: Username =
usernameService
.getUserNameById(id)
?: throw UserException("No username")
val subscription: Subscription =
subscriptionService
.getSubscriptionByUserId(id)
?: throw UserException("No subscription")
return User(id, username.content, subscription)
}
}
Focal test
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.mockito.Mockito
class UserServiceTest {
private val usernameService: UsernameService = Mockito.mock(UsernameService::class.java)
private val subscriptionService: SubscriptionService = Mockito.mock(SubscriptionService::class.java)
private val userService = UserService(usernameService, subscriptionService)
#Test
fun `getUserNameById throws exception if username is null`() {
// setup mocks
Mockito.`when`(userService.fetchUserById(1)).thenReturn(null)
// whenever
val userException: UserException = assertThrows { userService.fetchUserById(1) }
assert(userException.message == "No username")
Mockito.verify(userService).fetchUserById(1)
}
}
build.gradle
plugins {
id("org.springframework.boot") version "2.7.5"
id("io.spring.dependency-management") version "1.0.15.RELEASE"
kotlin("jvm") version "1.6.21"
kotlin("plugin.spring") version "1.6.21"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
I have tried different forms of that assertThrows and looked at other online documentation.
It should notice the exception and then pass.
I have a Spring Boot Gradle project using Spring Data MongoDB.
In order to generate the query type classes, I have to run the gradle build task.
Is there a way for creating the query type classes when saving the file in IntelliJ? I have already enabled annotation processing in the project.
I would like to have a behavior like the lombok plugin, where it is not needed to build the project to see the changes.
Below is my build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.franzbecker:gradle-lombok:1.11")
classpath("gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.9")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "io.franzbecker.gradle-lombok"
apply plugin: "com.ewerk.gradle.plugins.querydsl"
group = 'com.henrique'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile("com.querydsl:querydsl-mongodb:4.1.4")
compileOnly("com.querydsl:querydsl-apt:4.1.4")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
querydsl {
springDataMongo = true
querydslSourcesDir = "$buildDir/generated/source/app/main"
}
sourceSets {
main {
java {
srcDir "$buildDir/generated/source/app/main"
}
}
}
Here is my domain entity:
#Data
#Builder
#Document
public class Customer {
#Id
private String id;
private String firstName;
private String lastName;
private String zipCode;
}
And here is the query type generated:
#Generated("com.querydsl.codegen.EntitySerializer")
public class QCustomer extends EntityPathBase<Customer> {
private static final long serialVersionUID = -1386833698L;
public static final QCustomer customer = new QCustomer("customer");
public final StringPath firstName = createString("firstName");
public final StringPath id = createString("id");
public final StringPath lastName = createString("lastName");
public final StringPath zipCode = createString("zipCode");
public QCustomer(String variable) {
super(Customer.class, forVariable(variable));
}
public QCustomer(Path<? extends Customer> path) {
super(path.getType(), path.getMetadata());
}
public QCustomer(PathMetadata metadata) {
super(Customer.class, metadata);
}
}
I'm trying to build a simple api with spring boot and kotlin. When I make a request to save a new user everything goes well, a new user is persisted, but response body is empty. I don't know why, I return the new user. Please help me to understand why Jackson isn't serializing my kotlin class.
I can assure that the user returned is not null.
Entity:
#Entity
data class User(#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private val id: Long = 0L,
private var createdAt: LocalDateTime = LocalDateTime.now(),
private var enabled: Boolean = false,
private val username: String = "",
private val password: String = "",
private val name: String = "") {
#PrePersist
private fun onCreate() {
this.enabled = true
this.createdAt = LocalDateTime.now();
}
}
Controller:
#RestController
#RequestMapping("users")
class UserController {
#Autowired
private lateinit var userService: UserService
#PostMapping
fun save(#RequestBody user: User): User {
return this.userService.save(user)
}
}
build.gradle:
buildscript {
ext {
kotlinVersion = '1.2.20'
springBootVersion = '2.0.0.RC1'
}
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}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'br.com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
//JACKSON
compile "com.fasterxml.jackson.core:jackson-annotations"
compile "com.fasterxml.jackson.core:jackson-core"
compile "com.fasterxml.jackson.core:jackson-databind"
runtime "com.fasterxml.jackson.datatype:jackson-datatype-jdk8"
runtime "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
runtime "com.fasterxml.jackson.module:jackson-module-kotlin"
runtime('mysql:mysql-connector-java')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
application.properties
#DATA SOURCE
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc\:mysql\://localhost:3307/kotlin-library
spring.datasource.username = root
spring.datasource.password =
#JPA
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
#SERVER
server.servlet.context-path=/
#JACKSON
spring.jackson.serialization.indent-output=true
spring.jackson.serialization.write-dates-as-timestamps=false
spring.jackson.serialization.write-durations-as-timestamps=false
Everything in your data class is private. Typically serialization ignores private members in a class. If you make the necessary fields you desire to get serialized public, or just remove the private keyword I'm betting it works for you.
I am writing a custom plugin for Gradle. I want to be able to have:
serviceDependencies {
service name: 'service1', version: '1.0'
service name: 'service2', version: '1.1'
}
In my Plugin implementation (in Java) I have:
public void apply(final Project project) {
project.getExtensions().create("serviceDependencies", Services.class);
project.getExtensions().create("service", Service.class);
}
And Service.java:
public class Service {
private String name;
private String version;
public Service(final String name, final String version) {
this.name = name;
this.version = version;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getVersion() {
return this.version;
}
public void setVersion(final String version) {
this.version = version;
}
}
When I try use this plugin I get:
java.lang.IllegalArgumentException: Could not find any public constructor for class com.xxx.xxx.Service_Decorated which accepts parameters [].
This still happens when I remove serviceDependencies/Services.java from the picture.
If I remove the Service constructor or remove the arguments.
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method service() for arguments [{name=service1, version=1.0}] on root project ...
Obviously my pojo is being decorated, but not quite with the correct constructor. How can I get the constructor to work how I want in my build.gradle script?
A second and independent question is what should Services.java look like?
I would only register one extension for serviceDependencies {} that exposes functions to register your services:
public class Services {
void service(String name, String version) { /* new Service(...) */ }
}
project.getExtensions().create("serviceDependencies", Services.class);
This would allow Java, Kotlin and Groovy consumer to do something like:
serviceDependencies {
service 'service1', '1.0'
service 'service2', '0.1'
}
Then if you want to support Groovy named arguments you'd need to add:
public class Services {
void service(String name, String version) { /* new Service(...) */ }
void service(Map<String, String> namedArguments) {
service(namedArguments.get("name"), namedArguments.get("version"))
}
}
This would allow Groovy consumers to do:
serviceDependencies {
service name: 'service1', version: '1.0'
service name: 'service2', version: '0.1'
}
I have a spring-boot project and I'm using spring data rest with it. My build.gradle file looks like this. As you can see I did everything by the manual (well, apparently not everything).
What I want is to have /profile link and ability to get json-schema for all endpoints that I'm publishing. Instead I have /apls link. So I've checked spring-data-rest manual for <2.4 version and it doesn't mention neither /profile link nor json-schema. So I've figured that I'm not using the latest version of spring-data-rest.
I've added spring boot gradle plugin and I'm not specifying version for spring-boot-data-rest dependency. I've also tried to add org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE dependency.
But that apparently doesn't work, because I still have /alps link instead of /profile link.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'settings'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
dependencies {
compile group: 'org.zeromq', name: 'jeromq', version: '0.3.5'
compile group: 'org.json', name: 'json', version: '20141113'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'org.skyscreamer', name: 'jsonassert', version: '1.2.3'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-hateoas'
compile group: 'postgresql', name: 'postgresql', version:'9.1-901-1.jdbc4'
compile("org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE")
runtime group: 'com.h2database', name: 'h2', version:'1.4.187'
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude(module: 'commons-logging')
}
}
EDIT1:
I've found that if I'm not including dependency
compile("org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE")
Than gradle using spring-data-rest 2.2.3 or something like that.
But when I'm including that dependency it uses 2.4.0 like it should be, but then my test is failing for some reason.
My test looks like that
package demo;
import demo.settings.DemoApplication;
import demo.settings.processing.Channel;
import demo.settings.processing.ChannelMode;
import demo.settings.processing.ChannelsController;
import demo.settings.processing.ChannelRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import java.util.List;
import static org.junit.Assert.*;
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = DemoApplication.class)
public class DemoApplicationTests {
final String BASE_URL = "http://localhost:8080/";
private MockMvc mockMvc;
#Autowired
private ChannelsController controller;
#Autowired
private ChannelRepository repository;
#Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}
#Test
public void setChannels() {
Channel exampleChannel = new Channel(ChannelMode.AUTO, 1, 1, 1, false, 0);
controller.setChannels(0, 10, exampleChannel);
List<Channel> allChannels = repository.findAllByOrderByBinIndexAsc();
for (int i = 0; i <= 10; i++) {
Channel ch = allChannels.get(i);
assertEquals(ch.getBinIndex(), i);
assertEquals(ch.getC1(), exampleChannel.getC1(), 0);
assertEquals(ch.getC2(), exampleChannel.getC2(), 0);
assertEquals(ch.getManualCoefficient(), exampleChannel.getManualCoefficient(), 0);
assertEquals(ch.getMode().toString(), exampleChannel.getMode().toString());
assertEquals(ch.isExcluded(), exampleChannel.isExcluded());
}
exampleChannel.setC1(100);
controller.setChannels(0, 11, exampleChannel);
allChannels = repository.findAllByOrderByBinIndexAsc();
for (int i = 0; i <= 11; i++) {
Channel ch = allChannels.get(i);
assertEquals(ch.getBinIndex(), i);
assertEquals(ch.getC1(), exampleChannel.getC1(), 0);
assertEquals(ch.getC2(), exampleChannel.getC2(), 0);
assertEquals(ch.getManualCoefficient(), exampleChannel.getManualCoefficient(), 0);
assertEquals(ch.getMode().toString(), exampleChannel.getMode().toString());
assertEquals(ch.isExcluded(), exampleChannel.isExcluded());
}
}
}
Here is my repository
#RepositoryRestResource(path="dts_stm32_settings")
interface DtsStm32SettingsRepository extends PagingAndSortingRepository<DtsStm32Settings, Long> {
}
Here is my Model
package demo.settings.data_collection.stm;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* Created by michael on 11/09/15.
*/
#Entity
public class DtsStm32Settings extends Stm32Settings {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#NotNull #Min(value=0) #Max(value=65535)
private int firstChannelDac;
#NotNull #Min(value=0) #Max(value=65535)
private int secondChannelDac;
#NotNull #Min(value=0) #Max(value=65535)
private int dil;
#NotNull
private CommutatorChannel commutatorChannel;
#NotNull #Min(value=0) #Max(value=65535)
private int firstChannelPwm;
#NotNull #Min(value=0) #Max(value=65535)
private int zeroChannelPwm;
public DtsStm32Settings() {
}
public DtsStm32Settings(
int firstChannelShift,
int secondChannelShift,
int firstChannelGain,
int secondChannelGain,
int firstChannelSlope,
int secondChannelSlope,
boolean led,
boolean firstChannelDurationBit,
boolean secondChannelDurationBit,
int firstChannelDac,
int secondChannelDac,
int dil,
CommutatorChannel commutatorChannel,
int firstChannelPwm,
int zeroChannelPwm,
boolean pulsedPumpMode,
int durationOn,
int durationOff
) {
super(firstChannelShift, secondChannelShift, firstChannelGain, secondChannelGain, firstChannelSlope, secondChannelSlope, led, firstChannelDurationBit, secondChannelDurationBit);
this.firstChannelDac = firstChannelDac;
this.secondChannelDac = secondChannelDac;
this.dil = dil;
this.commutatorChannel = commutatorChannel;
this.firstChannelPwm = firstChannelPwm;
this.zeroChannelPwm = zeroChannelPwm;
this.pulsedPumpMode = pulsedPumpMode;
this.durationOn = durationOn;
this.durationOff = durationOff;
}
#NotNull
private boolean pulsedPumpMode;
#NotNull #Min(value=1) #Max(value=65535)
private int durationOn;
#NotNull #Min(value=0) #Max(value=65535)
private int durationOff;
public int getFirstChannelPwm() {
return firstChannelPwm;
}
public void setFirstChannelPwm(int firstChannelPwm) {
this.firstChannelPwm = firstChannelPwm;
}
public int getZeroChannelPwm() {
return zeroChannelPwm;
}
public void setZeroChannelPwm(int zeroChannelPwm) {
this.zeroChannelPwm = zeroChannelPwm;
}
public int getFirstChannelDac() {
return firstChannelDac;
}
public void setFirstChannelDac(int firstChannelDac) {
this.firstChannelDac = firstChannelDac;
}
public int getSecondChannelDac() {
return secondChannelDac;
}
public void setSecondChannelDac(int secondChannelDac) {
this.secondChannelDac = secondChannelDac;
}
public int getDil() {
return dil;
}
public void setDil(int dil) {
this.dil = dil;
}
public CommutatorChannel getCommutatorChannel() {
return commutatorChannel;
}
public void setCommutatorChannel(CommutatorChannel commutatorChannel) {
this.commutatorChannel = commutatorChannel;
}
public boolean isPulsedPumpMode() {
return pulsedPumpMode;
}
public void setPulsedPumpMode(boolean pulsedPumpMode) {
this.pulsedPumpMode = pulsedPumpMode;
}
public int getDurationOn() {
return durationOn;
}
public void setDurationOn(int durationOn) {
this.durationOn = durationOn;
}
public int getDurationOff() {
return durationOff;
}
public void setDurationOff(int durationOff) {
this.durationOff = durationOff;
}
}
package demo.settings.data_collection.stm;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* Created by michael on 11/09/15.
*/
#JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS, include=JsonTypeInfo.As.PROPERTY, property = "type")
#JsonSubTypes({#JsonSubTypes.Type(DtsStm32Settings.class)})
abstract class Stm32Settings {
#NotNull
#Min(value=0) #Max(value=65535)
protected int firstChannelShift;
#NotNull
#Min(value=0) #Max(value=65535)
protected int secondChannelShift;
#NotNull
#Min(value=0) #Max(value=65535)
protected int firstChannelGain;
#NotNull
#Min(value=0) #Max(value=65535)
protected int secondChannelGain;
#NotNull
#Min(value=0) #Max(value=65535)
protected int firstChannelSlope;
#NotNull
#Min(value=0) #Max(value=65535)
protected int secondChannelSlope;
#NotNull
protected boolean led;
#NotNull
protected boolean firstChannelDurationBit;
#NotNull
protected boolean secondChannelDurationBit;
protected Stm32Settings() {
}
public int getFirstChannelShift() {
return firstChannelShift;
}
public void setFirstChannelShift(int firstChannelShift) {
this.firstChannelShift = firstChannelShift;
}
public int getSecondChannelShift() {
return secondChannelShift;
}
public void setSecondChannelShift(int secondChannelShift) {
this.secondChannelShift = secondChannelShift;
}
public int getFirstChannelGain() {
return firstChannelGain;
}
public void setFirstChannelGain(int firstChannelGain) {
this.firstChannelGain = firstChannelGain;
}
public int getSecondChannelGain() {
return secondChannelGain;
}
public void setSecondChannelGain(int secondChannelGain) {
this.secondChannelGain = secondChannelGain;
}
public int getFirstChannelSlope() {
return firstChannelSlope;
}
public void setFirstChannelSlope(int firstChannelSlope) {
this.firstChannelSlope = firstChannelSlope;
}
public int getSecondChannelSlope() {
return secondChannelSlope;
}
public void setSecondChannelSlope(int secondChannelSlope) {
this.secondChannelSlope = secondChannelSlope;
}
public boolean isLed() {
return led;
}
public void setLed(boolean led) {
this.led = led;
}
public boolean isFirstChannelDurationBit() {
return firstChannelDurationBit;
}
public void setFirstChannelDurationBit(boolean firstChannelDurationBit) {
this.firstChannelDurationBit = firstChannelDurationBit;
}
public boolean isSecondChannelDurationBit() {
return secondChannelDurationBit;
}
public void setSecondChannelDurationBit(boolean secondChannelDurationBit) {
this.secondChannelDurationBit = secondChannelDurationBit;
}
public Stm32Settings(
int firstChannelShift,
int secondChannelShift,
int firstChannelGain,
int secondChannelGain,
int firstChannelSlope,
int secondChannelSlope,
boolean led,
boolean firstChannelDurationBit,
boolean secondChannelDurationBit
) {
setFirstChannelShift(firstChannelShift);
setSecondChannelShift(secondChannelShift);
setFirstChannelGain(firstChannelGain);
setSecondChannelGain(secondChannelGain);
setFirstChannelSlope(firstChannelSlope);
setSecondChannelSlope(secondChannelSlope);
setLed(led);
setFirstChannelDurationBit(firstChannelDurationBit);
setSecondChannelDurationBit(secondChannelDurationBit);
}
}
And here is error which tells me about nothing
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stm32Controller': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private demo.settings.data_collection.stm.DtsStm32SettingsRepository demo.settings.data_collection.stm.Stm32Controller.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dtsStm32SettingsRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:104)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
... 45 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private demo.settings.data_collection.stm.DtsStm32SettingsRepository demo.settings.data_collection.stm.Stm32Controller.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dtsStm32SettingsRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 60 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dtsStm32SettingsRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 62 more
Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 72 more
Try specifying Spring Data release train instead:
dependencyManagement {
imports {
...
mavenBom "org.springframework.data:spring-data-releasetrain:Gosling-RELEASE"
}
}
Then just compile the spring-data starters you need without specifying the version!