我是 Spring 新手,每当我尝试运行 Spring Boot 主脚本时都会收到以下错误消息。
***************************
APPLICATION FAILED TO START
***************************
Description:
Field testrepo in com.online.XXX.app.dao.TestDAO required a bean
named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
下面是我的 DAO 类:
@Service
public class TestDAO
{
@Autowired
private TestRep testrepo;
public List<E2ETestsDTO> finaAll() {
return testrepo.findAll();
}
}
我有如下所示的 pojo 类:
@Entity
@Table(name = "testXXX")
@EntityListeners(AuditingEntityListener.class)
public class E2ETestsDTO
{
@NotBlank
private String test_id;
@NotBlank
private String test_name;
public String getTest_id()
{
return test_id;
}
public void setTest_id(String test_id)
{
this.test_id = test_id;
}
public String getTest_name()
{
return test_name;
}
public void setTest_name(String test_name)
{
this.test_name = test_name;
}
}
下面是jpa存储库:
@Repository
public interface TestRep extends JpaRepository<E2ETestsDTO, Long>
{
}
以下是 Controller 类文件:
@RestController
@RequestMapping("/amzonrunner")
public class TestController
{
@Autowired
TestDAO testdao;
@GetMapping("/sample")
public List<E2ETestsDTO> getAllTestRecords()
{
return testdao.finaAll();
}
}
主要代码如下:
@SpringBootApplication
@EnableJpaAuditing
//@EnableJpaRepositories("com.online.xxx.app")
public class TestApplication
{
public static void main(String args[])throws Exception
{
SpringApplication.run(TestApplication.class);
}
}
有任何线索可以帮助我解决此问题吗?为什么启动失败。
最佳答案
我在 application.properties 中被赋予了错误的值。
Before:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect;
After:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
还删除了 @Entity 注释。
现在工作正常。
关于java - 无法执行 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50543751/