简体   繁体   English

如何让 Eclipselink 在 Spring Boot 应用程序中工作

[英]How can I get Eclipselink working in a Spring Boot application

copied my boot log to a gist because it's too long for SE.我的启动日志复制到要点,因为它对 SE 来说太长了。

here's what I suspect is the important part of the message.我怀疑这是消息的重要部分。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 145 more

also here's my pom.xml这也是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://maven.apache.org/POM/4.0.0"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.xenoterracide</groupId>
<artifactId>rpf</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.8.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <!--
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.7.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.2</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1102-jdbc41</version>
    </dependency>
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

<properties>
    <!-- use UTF-8 for everything -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <start-class>com.xenoterracide.rpf.Application</start-class>
    <java.version>1.8</java.version>
</properties>

<build>
    <plugins>
        <plugin>
            <artifactId>eclipselink-staticweave-maven-plugin</artifactId>
            <groupId>au.com.alderaan</groupId>
            <version>1.0.4</version>
            <executions>
                <execution>
                    <goals>
                        <goal>weave</goal>
                    </goals>
                    <phase>process-classes</phase>
                    <configuration>
                        <logLevel>ALL</logLevel>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>eclipselink</artifactId>
                    <version>2.5.2</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>http://repo.spring.io/libs-release</url>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>http://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

</project>

I'm using IDEA with it's built in "make" to compile and start the app.我正在使用内置“make”的 IDEA 来编译和启动应用程序。

I tried adding this class, but it didn't appear to help我尝试添加这个 class,但它似乎没有帮助

class EntityManagerFactoryProducer {

@Produces
@ApplicationScoped
public EntityManagerFactory createEntityManagerFactory() {
  return Persistence.createEntityManagerFactory("my-presistence-unit");
}

public void close(@Disposes EntityManagerFactory entityManagerFactory) {
  entityManagerFactory.close();
}

@Produces
@RequestScoped
public EntityManager createEntityManager(EntityManagerFactory entityManagerFactory) {
  return entityManagerFactory.createEntityManager();
}

public void close(@Disposes EntityManager entityManager) {
  entityManager.close();
}
}

I ran into a similar issue where I received the same No bean named 'entityManagerFactory' is defined exception.我遇到了一个类似的问题,我收到了相同的 No bean named 'entityManagerFactory' is defined 异常。 My fix was to define the bean in my configuration class.我的修复是在我的配置 class 中定义 bean。

@Configuration
public class JpaConfiguration extends JpaBaseConfiguration {
...
    @Bean
    public EntityManagerFactory entityManagerFactory() {
        return Persistence.createEntityManagerFactory("my-persistence-unit");
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Spring Boot 中工作时,如何在 xml 定义中获取我的应用程序上下文 - How can i get my Application Context in xml defination while working in Spring Boot 如何在没有Spring Boot的情况下创建Spring Sleuth应用程序 - How can I create a Spring sleuth application without Spring boot 如何使用Spring Boot从Gradle获取应用程序版本和一些其他信息? - How can I get application version and some other info from gradle using Spring Boot? 如何让 PCF 应用程序管理器显示有关我检测为 Spring 引导应用程序的信息? - How can I get PCF App Manager to display information about my detected as Spring Boot Application? 使用 Java 调用 JS 文件,或者如何使用 spring 启动 web 应用程序在浏览器中获得响应 - Invoke JS file using Java or how can I get response in browser using spring boot web application 我如何在 docker 容器中使用 spring 引导应用程序获取 keycloak realm 证书 - How I can get keycloak realm certs using spring boot application in docker container 如何在Spring Boot 2应用程序中设置Tomcat unloadDelay? - How can I set Tomcat unloadDelay in a Spring Boot 2 application? 如何在 Spring Boot 应用程序中实现 Firestore 时间戳 - How can I implement Firestore timestamp in Spring Boot Application 如何在 Spring Boot 应用程序的每个请求上插入延迟? - How can I insert a delay on every request on a Spring Boot application? 如何减少Docker中的Spring Boot应用程序内存使用率? - How can i decrease Spring Boot application memory usage in Docker?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM