I am trying to create a project with microservices, but i get the error "variable X not initialized in the default constructor" when trying to use the annotation @RequiredArgsConstructor from Lombok. The only solutions found on the internet are to check Obtain processors from project classpath (see image below) but that did not solve it for me.
The root pom is:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ku.survey</groupId>
<artifactId>survey</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>21</java.version>
<spring-boot.version>3.2.5</spring-boot.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<!-- <flyway.version>10.15.0</flyway.version>-->
<postgresql.version>42.7.2</postgresql.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven.compiler.proc>full</maven.compiler.proc>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- MapStruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- <!– Flyway –>-->
<!-- <dependency>-->
<!-- <groupId>org.flywaydb</groupId>-->
<!-- <artifactId>flyway-database-postgresql</artifactId>-->
<!-- <version>${flyway.version}</version>-->
<!-- </dependency>-->
<!-- PostgreSQL -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>user</module>
<module>survey-template</module>
<module>experiment</module>
</modules>
</project>
And the pom for the user microservice is:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ku.survey</groupId>
<artifactId>survey</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>user</artifactId>
<name>Survey User Microservice</name>
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- DB -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Flyway engine -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<!-- <version>10.15.0</version>-->
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.flywaydb</groupId>-->
<!-- <artifactId>flyway-database-postgresql</artifactId>-->
<!-- <version>10.15.0</version>-->
<!-- </dependency>-->
<!-- MapStruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<scope>provided</scope>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include> <!-- Allow all resources, not just .sql -->
</includes>
</resource>
</resources>
</build>
</project>
Does anyone have any tips? I have been stuck on this for a while now.
This is an example of code that gets caught in the error:
@RequiredArgsConstructor
@Service
public class UserWebServiceImpl implements UserWebService {
private final UserMapper userMapper;
private final UserPortInServiceImpl createUserPortInService;
@Override
public void createAccount(CreateUserRequestDto createUserRequestDto) {
//validation service for the input
createUserPortInService.createUser(
userMapper.toCreateUserRequest(createUserRequestDto));
}
}
