我試圖注入eventRepository這是春數據倉庫在我的項目:定義HibernateExceptionTranslator:沒有在bean工廠找到持久性的異常轉化
public class App {
protected static EntityManagerFactory factory;
@Autowired
protected EventRepository eventRepository;
public void execute() {
Event foo = eventRepository.findBySlug("abraxas");
}
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("beans.xml");
App runner = (App) context.getBean("AppBean");
runner.execute();
}
}
的beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean id="AppBean" class="org.app.App"></bean>
<jpa:repositories base-package="org.app.repository" />
</beans>
但是,當我運行它我得到以下異常:
java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation. at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators
在一些評論中,我發現我需要「c圖HibernateExceptionTranslator
「,但我沒有設法找出如何。
我正在嘗試關注official documentation,它沒有提及配置HibernateExceptionTranslator
。
感謝