Я новичок в Spring и получаю сообщение об ошибке ниже всякий раз, когда пытаюсь запустить свой основной скрипт загрузки Spring.
***************************
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>
{
}
Ниже приведен файл класса контроллера:
@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);
}
}
Любые лиды помогут мне решить эту проблему? почему его не удалось запустить.
Как правило, это означает, что у вас не включен стартер JPA.
У меня есть зависимость ниже в pom.xml <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-data-jpa </artifactId> </dependency>




Мне дали неправильное значение в application.properties.
Before:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect;
After:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Также удалена аннотация @Entity.
Теперь он работает нормально.
Он кричит изо всех сил:
Field productrepo in com.online.paypal.app.dao.ProductDAO required a bean named 'entityManagerFactory' that could not be found.