【发布时间】: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
请帮助我。谢谢大家。
【问题讨论】:
-
也许你可以从这个链接中找到一些答案:stackoverflow.com/questions/50190952/…
标签: java spring spring-boot