有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法执行spring启动应用程序

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

下面是我的刀课:

@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> 
 {

 }

以下是控制器类文件:

    @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);
    }

  }

有什么线索能帮我解决这个问题吗?为什么它没能启动


共 (1) 个答案

  1. # 1 楼答案

    我在申请时被赋予了错误的价值。财产

    Before:
    
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect;
    
    After:
    
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    

    还删除了@Entity注释

    现在它运行良好