I am getting cannot resolve symbol for the following in my intelliJ project:
Data, Lombok, Component, beans, http, util
My Class
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
#Component
#ConfigurationProperties("c")
#Data
public class CP {
private String maxTasks;
private String subscribeTo;
}
My POM
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
Try
File -> Settings -> search for “Annotations” -> Enable annotations -> Select the “Enable annnotations”
Apply and Ok and then restart IntelliJ once.
To make work propertly lombok on intellij it is necessary to use the extension
https://plugins.jetbrains.com/plugin/6317-lombok
Related
I am developing a Quarkus service application let's call it Project2, this application depends on Project1 which has the Book class with Validation Annotations.
When an invalid JSON is provided then I do not get the invalid message from the Book class. However, if I place the Book class within Poject2 directly without any dependency then I get the error messages.
I would like to know how to get the error messages from the Dependency class which are coming from JAR?
Following is my Project2 which has the BookService:
import org.project1.com.Book;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
#Path("/api")
public class BookService {
#Path("/generateTestData")
#POST
#Consumes(MediaType.APPLICATION_JSON)
public void generateTestData(#Valid final Book book){
System.out.println("After Successful Validation : " + book.toString());
}
}
Following is my Project1 Book class:
import lombok.Data;
import lombok.ToString;
import javax.validation.Valid;
import java.util.List;
#Data
#ToString
public class Book {
#NotNull(message="Book ID cannot be NULL")
#Min(value = 1, message="Book ID cannot be less than 1")
private int bookId;
#NotNull(message="Author name cannot be NULL")
private String author;
}
When I make a invalid request from Postman to http://localhost:8080/api/generateTestData then I do not get any validation messages (bookId should be >= 1 to be a valid input):
{
"bookId" : 0,
"author" : "Batman"
}
Can someone please let me know what's wrong here and how can I fix the issue? I have added the following dependency within my pom.xml:
<dependencies>
<dependency>
<groupId>org.project1.com</groupId>
<artifactId>project1</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
</dependencies>
I think y need to add this dependency to get your rest endpoint work otherwise y will get an error invalid MediaType from the resteasy library
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
When you add the dependency, Your endpoint function will be called and you will get 400 (Bad request) and the details of the invalid constraints returned in the response.
I'm trying to create a project that uses Hibernate Panache and Rest, similar to the quickstart on https://github.com/quarkusio/quarkus-quickstarts/tree/master/hibernate-orm-panache-resteasy.
When I try to #Post an entity that extends PanacheEntity, as shown below, I get the following error:
javax.ws.rs.ProcessingException: RESTEASY008200: JSON Binding deserialization error: Can't create instance
Entity
#Entity
#Cacheable
class Trade extends PanacheEntity {
#Column(length = 40, unique = true)
String name;
}
Rest resource
import javax.enterprise.context.ApplicationScoped;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
#Path("/trades")
#ApplicationScoped
#Produces("application/json")
#Consumes("application/json")
public class TradeReporterResource {
#POST
#Transactional
public Response add(Trade trade) {
System.out.println("begin");
//t.closePrice = trade.closePrice;
System.out.println("persisting");
trade.persist();
System.out.println("persisted");
return Response.ok(trade).build();
}
}
Pom dependencies
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
</dependencies>
Problem appears to be with Penache
When I remove the extends PanacheEntity from the Trade entity, then at least I can POST successfully.
The problem turns out to be rather simple, all you need to do is make class Trade a public class.
It should be noted that this is not a Quarkus limitation, but a JSON-B limitation (which requires de-serialized classes to have a public or protected no-arg constructor - see section 3.7 of the JSON-B spec)
I have class that one of it's parameters i want to set from properties file:
import org.springframework.beans.factory.annotation.Value;
(..)
#Getter
#Setter
#NoArgsConstructor
public class ConvertNonStandardOfferRequestDtoWrapper {
private ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto;
#Value("true")
private boolean documentPrintoutsRequired;
public ConvertNonStandardOfferRequestDtoWrapper(ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto) {
this.convertNonStandardOfferRequestDto = convertNonStandardOfferRequestDto;
}
}
What i see inside constructor is that documentPrintoutsRequired is false instead of true. I see that when debuging and setting breakpoint inside constructor. And i have a pom file for this module:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>x</groupId>
<artifactId>policy</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>
<artifactId>policy-api</artifactId>
<dependencies>
<dependency>
<groupId>x</groupId>
<artifactId>common-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
(...)
</build>
</project>
I am wonderning why #value does not work correctly ?
I'd advise you use constructor inyection for all attributes, this way you'll see the injected #Value during construction time.
Besides the class must be a Spring bean, so add #Component annotation:
#Component
#Getter
#Setter
#NoArgsConstructor
public class ConvertNonStandardOfferRequestDtoWrapper {
private ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto;
private boolean documentPrintoutsRequired;
public ConvertNonStandardOfferRequestDtoWrapper(ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto,
#Value("${yourproperty}") boolean documentPrintoutsRequired) {
this.convertNonStandardOfferRequestDto = convertNonStandardOfferRequestDto;
this.documentPrintoutsRequired = documentPrintoutsRequired;
}
}
You can read the value from properties file, such as
username = Tom.
use #Value in Java, you can set a default value like this:
#Value("${username:Jack}")
If the username does not exist in properties file, it will be "Jack".
Did you try this:
#Value("${yourPropInPropertiesFile}")
private boolean documentPrintoutsRequired;
The following code
package com.inthemoon.snippets.rxjava;
import io.reactivex.*;
public class HelloWorld {
public static void main(String[] args) {
Flowable.just("Hello world").subscribe(System.out::println);
}
}
causes the following compile error
Error:(9, 15) java: cannot access org.reactivestreams.Publisher
class file for org.reactivestreams.Publisher not found
POM dependency is following
<dependencies>
<!-- https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxjava -->
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
Same error and simple solution - add this to your app Gradle file
implementation 'io.reactivex.rxjava2:rxjava:2.1.14'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
The same happened to me.I have solved it.
add the dependeny follows:
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<version>1.0.0</version>
</dependency>
This has been fixed since 2.0.5 by github.com/ReactiveX/RxJava/issues/5014 2.1.1, is the latest version as of this answer
Solution :
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.1</version>
</dependency>
In pom.xml I use spring-tx-4.1.4.RELEASE.jar, but maven compiles the project with an error:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project transaction: Compilation failure
\p4_projects\transaction\src\main\java\com\sick\dao\hibernate\DeviceModelDaoHibernate.java:[25,15] cannot find symbol symbol : method value()
location: #interface org.springframework.transaction.annotation.Transactional
I cannot find the reason. Dependency Hierarchy shows correct version 4.1.4 for all spring dependencies. I have the same result with 4.1.3.
I'll appreciate your help.
Thanks,
Elena
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.sick.dao.DeviceModelDao;
import com.sick.model.DeviceModel;
#Repository
#Transactional(value = "primary")
public class DeviceModelDaoHibernate implements DeviceModelDao {
private SessionFactory sessionFactory;
public DeviceModelDaoHibernate() {
}
public DeviceModelDaoHibernate(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
#Override
public void save(DeviceModel deviceModel) {
sessionFactory.getCurrentSession().saveOrUpdate(deviceModel);
}
}
pom.xml is too big to post here, therefore I publish only versions of dependencies:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<red5-server.version>1.0.2-SNAPSHOT</red5-server.version>
<red5-client.version>1.0.2-SNAPSHOT</red5-client.version>
<camel.version>2.14.1</camel.version>
<hibernate.version>4.3.8.Final</hibernate.version>
<spring.version>4.1.4.RELEASE</spring.version>
<spring-security.version>3.2.5.RELEASE</spring-security.version>
<spring-integration.version>3.0.0.RELEASE</spring-integration.version>
<slf4j.version>1.7.5</slf4j.version>
<mina.version>2.0.7</mina.version>
<logback.version>1.0.13</logback.version>
<junit.version>4.10</junit.version>
<cargo.host>localhost</cargo.host>
<cargo.port>25888</cargo.port>
<cargo.wait>false</cargo.wait>
<tomcat.version>6.0.14</tomcat.version>
</properties>
....
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<type>jar</type>
</dependency>
</dependencies>
Using Eclipse?
Try Maven clean > Project clean > Maven install.
Error is suspicious indeed, I think you do not have problem with code but with Maven.
Thanks to everybody, I have already resolved that issue. In pom.xml I've placed all org.springframework dependencies before org.hibernate dependencies and the problem has gone.
Same problem here: the #Transactional was wrongly coming from an old "spring-dao" library, wich was a transitive dependency for "spring-hibernate3" but I wanted it from "spring-tx".
Solved it by moving the "spring-tx" dependency before the "spring-hibernate3" (I supposed I could have used exclusions too).
Use mvn dependency:tree to visualize transitive dependencies.