私は、hibernate 4とmysqlのためのスプリングブートアプリケーションの設定作業用のバージョンを探しています。私はspring.config、persistence.xml、およびpomファイルの異なる組み合わせに悩まされています
私は:(昨日から私の構成で、次のエラーを取得しています:
!org.springframework.beans.factory.BeanCreationException:エラー は「EntityManagerFactoryを」クラスパスに定義されて リソースを名前でBeanを作成します[春-config.xmlに]:initメソッドの呼び出しに失敗しました。ネストされた 例外はjava.lang.IllegalStateExceptionです:JPAはPersistenceProvider がnullのEntityManagerFactoryを返された - あなたのJPAプロバイダの設定を確認し
これは私のpersistence.xml
ファイル
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="my-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.PersistenceProvider</provider>
<class>com.crossover.trial.travelmanagementportal.model.Order</class>
<class>com.crossover.trial.travelmanagementportal.model.User</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="12345678"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/travelmanagement" />
<property name="hibernate.default_schema" value="travelmanagement" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
であり、これはあなたがあなたのpom.xmlに
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
を使用しますが、単純にあなたの接続を設定することができた場合は、私のspring.config
ファイル
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/tx">
<context:annotation-config />
<context:property-placeholder location="classpath:application.properties" />
<context:component-scan base-package="com.crossover.trial.travelmanagementportal" />
<!-- For @Transactional annotations -->
<!-- This makes Spring perform @PersistenceContext/@PersitenceUnit injection: -->
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<!-- Drives transactions using local JPA APIs -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="MYSQL"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="my-pu" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaAdapter"/>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/travelmanagement" />
<property name="username" value="root" />
<property name="password" value="xxxx" />
</bean>
<bean id="currentUserDetailsService" class="com.crossover.trial.travelmanagementportal.service.CurrentUserDetailsService" />
<bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<bean id="authProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="currentUserDetailsService" />
<property name="passwordEncoder" ref="encoder" />
</bean>
</beans>
ここでapplication.propertiesにspring.datasource ....を記述する必要がありますか? –
ファイル内のどこにでもあります。ファイルはクラスパスになければなりません:http://stackoverflow.com/questions/38775194/where-is-the-application-properties-in-spring-boot – MicD