【问题标题】:"Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled" when run Spring Boot project运行 Spring Boot 项目时,“启动 ApplicationContext 时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序”
【发布时间】:2021-06-09 05:14:26
【问题描述】:

这是我在运行 Spring Boot 程序时遇到的错误。

我的项目结构如下:

Student.java 只是模型类

还有StudentRepo.java我有


public interface StudentRepo extends JpaRepository<Student, Long>{

}

StudentService.java

@Service
@Transactional
public class StudentService {
    @Autowired
    private StudentRepo st;
    
    public List<Student> findAll()
    {
        return st.findAll();
    }
}

还有文件 TestServiceApplication.java

@SpringBootApplication
public class TestServiceApplication implements CommandLineRunner{

    private StudentService stu;
    public static void main(String[] args) {
        SpringApplication.run(TestServiceApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // TODO Auto-generated method stub
        List<Student> li = stu.findAll();
        li.forEach(System.out :: println);
    }

}

运行时出现如下错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-11 15:11:54.458 ERROR 22348 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner

请帮助我。谢谢大家。

【问题讨论】:

标签: java spring spring-boot


【解决方案1】:

IMO 存在一些相互冲突的依赖关系。除此之外,您的代码似乎存在一些问题:

....
@Autowired //missing
private StudentService stu;
....

别忘了扫描包裹。

@SpringBootApplication(scanBasePackages = {
        "com.example.demo"
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    • 2018-12-15
    • 2018-09-07
    • 2020-02-23
    • 2018-03-30
    相关资源
    最近更新 更多