当前位置: 首页 > 知识库问答 >
问题:

GWTSpring数据,JPA配置

姬寂离
2023-03-14

尝试基于以下内容设置应用程序时出错:SPRING-DATA-JPA, GWT项目。尝试在托管模式下运行时出现异常:

嵌套在org.springframework.beans.factory.BeanCreationException:创建名称为org.springframework.dao.annotation.的bean时出错:bean初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为'entityManagerFactory'的bean时出错,定义在URL[file:/**/www/WEB-INF/class/Application ationContext.xml]中:调用init方法失败;嵌套异常是javax.persistence.Perstemence Exception:[Perstemence Unit:默认]无法构建EntityManagerFactory:javax.validation.ValidationException:无法找到默认提供程序

这是我的应用程序上下文。xml:

<context:component-scan base-package="service"/>

<jpa:repositories base-package="service.repositories"
                  query-lookup-strategy="create-if-not-found"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="rollbackOnCommitFailure" value="true"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driver.classname}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.user}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="autoCommitOnClose" value="true"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
    <property name="packagesToScan" value="com.logicify.office.domain"/>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="true"/>
            <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQL82Dialect"/>
        </bean>
    </property>
</bean>

这里是pom。xml:

<modelVersion>4.0.0</modelVersion>
<groupId></groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Logicify Infrastructure</name>

<modules>
    <module>m-domain</module>
    <module>m-service</module>
    <module>m-calendar</module>
    <module>m-admin</module>
    <module>m-supply</module>
    <module>m-entry</module>
</modules>

<properties>
    <gwtVersion>2.5.0</gwtVersion>
    <spring.version>3.1.2.RELEASE</spring.version>
    <hibernate.version>4.1.7.Final</hibernate.version>
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <build.filter.file>test.properties</build.filter.file>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.0.2.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>

        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.0-801.jdbc4</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>

    </dependencies>
</dependencyManagement>

<dependencies>

    <!--GWT SDK-->
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>${gwtVersion}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>${gwtVersion}</version>
    </dependency>

    <!--Validation API-->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <classifier>sources</classifier>
    </dependency>

    <!--LOGGER-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

    <!--PROXY LIBS-->
    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>

    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.3</version>
    </dependency>

    <!-- TESTING -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>1.9.5-rc1</version>
    </dependency>
</dependencies>


<build>
    <finalName>logicify-infrastructure</finalName>
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
    <filters>
        <filter>${project.basedir}/../properties/${build.filter.file}</filter>
    </filters>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

         <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <webappDirectory>${webappDirectory}</webappDirectory>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                <execution>
                    <goals>
                        <goal>clean</goal>
                        <goal>compile</goal>
                        <goal>resources</goal>
                        <goal>generateAsync</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>

                <compileSourcesArtifacts>
                    <artifact>com.logicify.office:m-domain</artifact>
                    <artifact>com.logicify.office:m-admin</artifact>
                    <artifact>com.logicify.office:m-calendar</artifact>
                    <artifact>com.logicify.office:m-service</artifact>
                    <artifact>com.logicify.office:m-supply</artifact>
                </compileSourcesArtifacts>

                <runTarget>Entry.html</runTarget>
                <hostedWebapp>${webappDirectory}</hostedWebapp>
            </configuration>
            </plugin>
        </plugins>
</build>

没有GWT集成的相同配置工作正常。任何帮助都将是有用的!

共有2个答案

梁宪
2023-03-14

尝试添加hibernate验证程序。jar到类路径。GWT 2.5.0使用验证API(已包含在GWT SDK中),您需要为其提供一个实现。请参阅验证设置说明

陶高扬
2023-03-14

指定javax。正如Maksym所说,验证只提供您需要实现的接口

<!--Validation API-->
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
</dependency>

您需要一些hibernate验证程序版本

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.0.0.CR5</version>
</dependency>
 类似资料:
  • 我的设置有一个奇怪的问题,我不明白。我正在从事一个maven GWT项目,该项目在shell中运行良好(即mvn GWT:run按预期工作)。 然而,当我尝试在Eclipse中运行它(安装了m2e和gwt插件)时,我得到了一个classnotfoundexception。该类是一个实体类,在生成实体管理器时会发生异常。我检查了该类是否在持久性中声明。xml和我在pom中找不到任何排除项。xml或e

  • 我们正在寻找不同模块分别指定@ComponentScan、@EnableJpaRepositories和EntityManagerFactory的方法。setPackagesToScan。 我们将多个代码模块组合到Web应用程序中。此外,我们允许对基本代码进行客户特定的扩展,可以添加额外的包。在我的测试中,我发现我可以添加一个额外的java配置类,并且在@ComponentScan和@Enable

  • 我正在读《Web应用程序的专业Java——尼古拉斯·威廉姆斯》这本书的例子对Spring Data JPA有这样的配置: 但我一直在使用XML进行配置,我不知道如何仅将其转换为XML,到目前为止我已经有了这个 有谁能指导我如何转换这个吗? 谢谢

  • 我有两个实体。父母和孩子。 儿童知识库。JAVA 我试图通过标准找到子实体,它应该总是有父实体。 我得到一个例外,它试图在地址表中找到parentObj。 我找到了这个链接,并尝试了Joep给出的解决方案,但出现了相同的错误。 Spring数据JPA JpaSpecificationExecator EntityGgraph 我错过了什么。我无法理解为什么/如何在just Child对象中查找pa

  • 本文向大家介绍spring+Jpa多数据源配置的方法示例,包括了spring+Jpa多数据源配置的方法示例的使用技巧和注意事项,需要的朋友参考一下 今天临下班时遇到了一个需求,我的管理平台需要从不同的数据库中获取数据信息,这就需要进行Spring的多数据源配置,对于这种配置,第一次永远都是痛苦的,不过经历了这次的折磨,今后肯定会对这种配置印象深刻。我们这里简单回顾一下流程。 我们配置了两个数据库,

  • 如何正确配置Wildfly8.x JTA数据源,以便在EclipseLink和Microsoft的SQLServer数据库中使用JPA?