当我尝试运行我的应用程序时,出现错误:
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);
}
尝试在程序集文件(如 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>