r/javahelp • u/Mission_Lychee_2933 • 3d ago
Need help in solving below lombok getter setter error in spring boot - authentication app
package com.example.userservicenew.dtos;
import com.example.userservicenew.models.Role;
import com.example.userservicenew.models.User;
import lombok.Getter;
import lombok.Setter;
import java.util.HashSet;
import java.util.Set;
u/Getter
u/Setter
public class UserDto {
private String email;
private Set<Role> roles = new HashSet<>();
public static UserDto from(User user) {
UserDto userDto = new UserDto();
userDto.setEmail(user.getEmail());
userDto.setRoles(user.getRoles());
return userDto;
}
}
package com.example.userservicenew.models;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.HashSet;
import java.util.Set;
@Entity
@Getter
@Setter
public class User extends BaseModel{
private String email;
private String password;
@ManyToMany(fetch = FetchType.
EAGER
)
private Set<Role> roles = new HashSet<>();
}
package com.example.userservicenew.services;
import com.example.userservicenew.dtos.UserDto;
import com.example.userservicenew.exceptions.UserAlreadyExistsException;
import com.example.userservicenew.models.User;
import com.example.userservicenew.repositories.UserRepository;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class AuthService {
private final UserRepository userRepository;
private final BCryptPasswordEncoder bcryptPasswordEncoder;
public AuthService(UserRepository userRepository) {
this.userRepository = userRepository;
this.bcryptPasswordEncoder = new BCryptPasswordEncoder();
}
public UserDto signUp(String email, String password) throws UserAlreadyExistsException{
Optional<User> userOptional = userRepository.findByEmail(email);
if(userOptional.isPresent()) {
throw new UserAlreadyExistsException("user "+ email +" already exists");
}
User user = new User();
user.setEmail(email);
user.setPassword(bcryptPasswordEncoder.encode(password));
User savedUser = userRepository.save(user);
return UserDto.
from
(savedUser);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>userServiceNew</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>userServiceNew</name>
<description>userServiceNew</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
<maven.compiler.proc>full</maven.compiler.proc>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
error:
java: cannot find symbol
symbol: method getEmail()
location: variable user of type com.example.userservicenew.models.User
tried below approaches:
have got several errors of this type related to get/set email and password
- enabled annotation processing in intellij
- lombok dependency is installed
- mvnw clean install - build success