Intellij Idea Jpa Repository suggestion is not working - spring-boot

I created a Spring Boot project on Intellij Idea
here is my configuration
Spring Boot version: id 'org.springframework.boot' version '2.6.7'
Intellij Idea Build #IU-221.5080.210, built on April 12, 2022
here is my build.gradle file
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'net.ltgt.apt' version '0.21'
}
group = 'io.project'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = "17"
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'
implementation 'org.hibernate.validator:hibernate-validator:7.0.4.Final'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
targetCompatibility = JavaVersion.VERSION_17
and here is one of my classes that extends JpaRepository
#Repository
public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
List<CommentEntity> findAllByPostId(Long postId);
}
when I try to write my methods name I do not get suggestions from JpaRepository
any idea why this is happening?

Related

Redis OM Spring - Gradle issue: not generating meta classes "com.redis.om.skeleton.models.Person$

I am trying to use gradle for this project https://redis.io/docs/stack/get-started/tutorials/stack-spring/. My build.gradle is this one:
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation "com.redis.om:redis-om-spring:0.6.4"
implementation "io.springfox:springfox-boot-starter:3.0.0"
implementation "io.springfox:springfox-swagger-ui:3.0.0"
}
test {
useJUnitPlatform()
}
I am getting the following err while build this project:
error: cannot find symbol
import com.redis.om.skeleton.models.Person$;
It seems META model classes are not being generated by gradle. I am using Intellij Community edition with java 17.
Any help would be appreciate.
I had to add the following to my build.gradle and it solved my issue:
annotationProcessor("com.redis.om:redis-om-spring:0.6.4")

MapStruct throws exception when try to build project

There is springboot application with gradle and try to convert one object to another using MapStruct, but there is exception in compile time
I added sctruct dependencies in build.gradle by instruction in bottom
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'my.bot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.6'
implementation 'javax.jws:javax.jws-api:1.1'
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
implementation 'org.mapstruct:mapstruct-processor:1.5.3.Final'
}
tasks.named('test') {
useJUnitPlatform()
}
tasks.withType(JavaCompile) {
options.compilerArgs = [
'-Amapstruct.suppressGeneratorTimestamp=true'
]
}
My interface look like this
#Mapper
public interface DeviceAgentMessageMapper {
#Mapping(source = "gamma", target = "message")
AgentMessage toAgentMessage(Device device);
}
But when try to start application or call build gradle job, there is error message:
The following options were not recognized by any processor: '[mapstruct.suppressGeneratorTimestamp]'
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException at DefaultListableBeanFactory.java:1801

How to fix Could not find or load main class in Spring boot gradle.build?

Im new in gradle and i receive and error about my main class is Could not find or load main class i tried to fix it but doest work.
plugins {
id 'org.springframework.boot' version '2.6.9'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.notification'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.3")
}
dependencies {
implementation 'io.awspring.cloud:spring-cloud-aws-context:2.3.1'
implementation 'io.awspring.cloud:spring-cloud-aws-autoconfigure:2.3.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-stream'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
springBoot {
mainClass = 'com.notification.NotificationServiceApplication'
}
Error
Error: Could not find or load main class com.notifcation.NotificationServiceApplication
Caused by: java.lang.ClassNotFoundException: com.notifcation.NotificationServiceApplication
Disregard this post question. I just restart my IDE

How to import local external jar having spring cloud vault client dependency

I have a "multi-module" Gradle project named "utils". In that, I have created a new sub-project that will be used as a client for Hashicorp's Vault. I'll use this jar to my Spring Boot microservices as a dependency.
The goal is to have a common configuration for Vault and use it in all the services.
My problem is when I try to auto-wire the VaultTemplate object (presuming it will be added from this jar), in one of my Spring Boot microservices (say secrets-management-service), I could not achieve that.
For development purposes, I have included the jar as a local dependency. I have included both the build.gradle files.
External Jar: vault-client
group = 'com.example.learning'
version = '1.0.0-SNAPSHOT'
buildscript {
ext {
springVersion = '2.4.4'
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springVersion}"
}
}
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = '1.8'
ext {
springCloudVersion = '2020.0.2'
}
repositories {
mavenCentral()
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-vault-config'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
Microservice: secrets-management-service
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example.learning'
version = ''
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
bootJar {
setArchivesBaseName("secret-management-service")
version("")
}
dependencies {
compile fileTree(dir: "${projectDir}/libs", include: "*.jar")
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
I found it myself. I had missed the below block in my vault-client jar and also forgot to remove "main" class.
bootJar {
enabled = false
}

AnnotationProcessor and dependencies

I'm using gradle / querydsl and JPA 2.1.
I would like to generate the querydsl metadata using APT (QEntities).
To do that I'm using the gradle-apt-plugin and gradle 4.7
In my project I configured the compileJava option using :
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("$projectDir/src/generated2/java")
}
In my dependencies I added
compile 'org.springframework.boot:spring-boot-starter-data-jpa'"
annotationProcessor "com.querydsl:querydsl-apt:$querydslVersion:jpa"
The spring starter adds the org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final jar that contains javax.persistence.Entity class to the compileClasspath.
When launching the compileJava task I got the error :
caused by: java.lang.NoClassDefFoundError: javax/persistence/Entity at com.querydsl.apt.jpa.JPAAnnotationProcessor.createConfiguration(JPAAnnotationProcessor.java:37)
Don't understand why the annotation processor cannot load this class.
In case somebody else is searching. This is my full solution (based on your response). The important parts are the net.ltgt.apt* plugins to activate the code generation also in eclipse, and the last three querydsl dependencies.
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins { // activates the automatic code generation
id 'net.ltgt.apt' version '0.18'
id 'net.ltgt.apt-eclipse' version '0.18'
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
runtimeOnly 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webflux'
// querydsl
annotationProcessor 'com.querydsl:querydsl-apt:4.1.3:jpa'
annotationProcessor 'org.springframework.boot:spring-boot-starter-data-jpa' // needed because the query dsl annotation processor doesn't recognize javax.persistence.Entity
compile 'com.querydsl:querydsl-jpa:4.1.3'
}

Resources