Spring 看不到 lombok 构造函数

问题描述 投票:0回答:1

当我尝试运行我的应用程序时,出现错误:

java: variable userRepository not initialized in the default constructor

这是出现问题的配置文件(事实证明,问题出在构造函数创建的所有注释上)

@Configuration
@RequiredArgsConstructor
public class AppConfig {

    private final UserRepository userRepository;


    @Bean
    public UserDetailsService userDetailsService() {
        return email -> userRepository.findByEmail(email)
                .orElseThrow(() -> new UsernameNotFoundException("User haven't found"));
    }
...

用户存储库:

public interface UserRepository extends JpaRepository<User, Long> {

    Optional<User> findByEmail(String email);

}
  • “启用注释处理”正在打开
  • 已经尝试过使现金无效
  • 尝试重新安装lombok插件
java spring-boot intellij-idea lombok
1个回答
0
投票

尝试在程序集文件(如 pom.xml)中添加注释处理器路径

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>{maven.compile.plugin.version}</version>
  <configuration>
    <annotationProcessorPaths>
      <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.