java - 无法执行 Spring Boot 应用程序

标签 java spring spring-boot

我是 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/

相关文章:

Java项目编译错误

java - 运行 Spring Web MVC 项目时的顺序是什么?

java - 更新 Gradle 项目库

java - SpringSecurityFilterChain 和执行器

spring-boot - Prometheus 端点是一个空白页 - 在 Spring Boot 应用程序中使用 kamon 和 Prometheus 报告器

java - 非静态 webapp 别名

java - 由socketRead0分配的字符串TLAB

java - 从 2 个不同的 Activity 启动相同的 Activity 并更新数据

java - BeanCreationException 和 NoClassDefFoundError : What am I missing in here?

java - 有没有办法让@Bean 创建的一些 bean 可区分?