小编gol*_*iga的帖子

Spring-boot + JPA EntityManager注入失败

在我的J2EE应用程序中,我尝试使用spring-boot和JPA技术,将EntityManager注入DAO层.但是,我有一些问题...我的用户CRUD存储库:

@Repository
public class UserRepositoryImpl implements UserRepository {

@PersistenceContext(unitName = "data")
private EntityManager entityManager;
// and crud methods
}
Run Code Online (Sandbox Code Playgroud)

我的spring-boot应用程序类:

@SpringBootApplication
public class App {
    public static void main(String [] args) {
        SpringApplication.run(App.class, args);
    }
Run Code Online (Sandbox Code Playgroud)

}

最后我的persistence.xml,位于src/main/resources/META-INF文件夹中:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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">
<persistence-unit name="data" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>com.example.domain.User</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.connection.autocommit" value="false" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
        <property name="hibernate.c3p0.min_size" value="4" />
        <property name="hibernate.c3p0.max_size" value="128" />
        <property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost:1433;databaseName=qwerty;sendStringParametersAsUnicode=false" />
        <property name="javax.persistence.jdbc.user" value="sa" />
        <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" …
Run Code Online (Sandbox Code Playgroud)

spring jpa cdi spring-boot

6
推荐指数
2
解决办法
3万
查看次数

标签 统计

cdi ×1

jpa ×1

spring ×1

spring-boot ×1