创建类路径资源中定义的名为“loadTimeWeaver”的 bean 时出错

问题描述 投票:0回答:0

我是 Spring Boot 的新手,希望得到一些帮助来解决这个错误。

我正在尝试通过 EclipseLink 从 Docker 容器连接到数据库。我希望能够将 JSON 数据存储在其中一个表中并从另一个表中检索 JSON 数据。在运行代码时,我遇到了这个错误。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.10</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>de.cibplus</groupId>
    <artifactId>cibplus-ng-vdp-GKZ</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>cibplus-ng-vdp-GKZ</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-jpa</artifactId>
         <exclusions>
            <exclusion>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-entitymanager</artifactId>
            </exclusion>
            <exclusion>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-core</artifactId>
            </exclusion>
         </exclusions>
      </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
         <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-devtools</artifactId>
         <scope>runtime</scope>
         <optional>true</optional>
      </dependency>
      <dependency> 
                        <groupId>javax.xml.bind</groupId> 
                        <artifactId>jaxb-api</artifactId> 
                        <version>2.3.0</version> 
</dependency>

      <dependency>
         <groupId>org.eclipse.persistence</groupId>
         <artifactId>org.eclipse.persistence.jpa</artifactId>
         <version>2.7.8</version>
      </dependency>
      <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </dependency>
        
        <!-- 
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        -->
        <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.22</version>
    <scope>provided</scope>
</dependency>
        <!-- <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <configuration>
      <executable>java</executable>
       <arguments>
           <argument>-Xmx1000m</argument>
           <argument>-javaagent:lib/eclipselink-${eclipselink.version}.jar</argument>
           <argument>-classpath</argument>
           <classpath/>
           <argument>my.App</argument>
       </arguments>
     </configuration>
   </plugin>
</plugins>
    </build>

</project>

JpaConfiguration.java

package de.cibplus.cibplusngvdpGKZ;

import java.util.Map;
import java.util.Properties;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager;

@Configuration
@EnableJpaAuditing
@EnableLoadTimeWeaving
@EnableAutoConfiguration
public class JpaConfiguration extends JpaBaseConfiguration {

    public JpaConfiguration(DataSource dataSource, JpaProperties props, ObjectProvider<JtaTransactionManager> txm) {
        super(dataSource, props, txm);
    }

    @Bean
    public EntityManagerFactory entityManagerFactory() {
        AbstractJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();

        vendorAdapter.setGenerateDdl(false);
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();

        Properties properties = new Properties();
        properties.setProperty("eclipselink.weaving", "static");
        factory.setJpaProperties(properties);
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("de.cibplus.cibplusngvdpGKZ.Repository");
        factory.afterPropertiesSet();

        return factory.getObject();
    }
    

    @Bean
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory());
        return txManager;
    }
 
    protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
        // TODO Auto-generated method stub
        return null;
    }

    protected Map<String, Object> getVendorProperties() {
        // TODO Auto-generated method stub
        return null;
    }
}
java spring-boot maven jpa eclipselink
© www.soinside.com 2019 - 2024. All rights reserved.