小编典典

创建bean'entityManagerFactory'时出错,嵌套的HibernateException:无法获取默认的Bean Validation工厂

java

有关此主题的问题很多,但似乎没有一个可以解决我的问题。

我尝试使用Maven,Spring,Hibernate和JPA和Mysql
5.5进行示例项目。这是一个测试桌面应用程序。我不知道我在哪里弄错了。mvn全新安装使构建成功。但是,当我运行时,我正在遵循以下异常。需要帮助。请参阅下面的代码。

> ************** BEGINNING PROGRAM **************
Feb 20, 2015 6:36:44 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@758fc9: startup date [Fri Feb 20 18:36:44 IST 2015]; root of context hierarchy
Feb 20, 2015 6:36:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [app-config.xml]
Feb 20, 2015 6:36:45 PM org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider registerDefaultFilters
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
Feb 20, 2015 6:36:45 PM org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider registerDefaultFilters
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
Feb 20, 2015 6:36:45 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [database.properties]
Feb 20, 2015 6:36:45 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Feb 20, 2015 6:36:45 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e91f5d: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,stockDao,stockService,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,dataSource,entityManagerFactory,jpaDialect]; root of factory hierarchy
Feb 20, 2015 6:36:46 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Feb 20, 2015 6:36:46 PM org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader determinePersistenceUnitRootUrl
INFO: apppersistence.xml should be located inside META-INF directory; cannot determine persistence unit root URL for class path resource [apppersistence.xml]
Feb 20, 2015 6:36:46 PM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory
INFO: Building JPA container EntityManagerFactory for persistence unit 'modalUnit'
[main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.2-Final
[main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.2-Final
[main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
[main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
[main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
[main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.5.2-Final
[main] INFO org.hibernate.ejb.Ejb3Configuration - Processing PersistenceUnitInfo [
    name: modalUnit
    ...]
[main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.prac.core.modal.Stock
[main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.prac.core.modal.Stock on table Stock
[main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
Feb 20, 2015 6:36:47 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e91f5d: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,stockDao,stockService,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,dataSource,entityManagerFactory,jpaDialect]; root of factory hierarchy
*********************** ERROR ****************************
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stockDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [app-config.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:341)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1073)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.prac.core.App.main(App.java:21)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [app-config.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:529)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
    ... 13 more
Caused by: org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:104)
    at org.hibernate.cfg.AnnotationConfiguration.applyBeanValidationConstraintsOnDDL(AnnotationConfiguration.java:477)
    at org.hibernate.cfg.AnnotationConfiguration.applyConstraintsToDDL(AnnotationConfiguration.java:429)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:403)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1453)
    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1081)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:677)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
    ... 26 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:95)
    ... 39 more
Caused by: java.lang.NoClassDefFoundError: org/apache/geronimo/osgi/locator/ProviderLocator
    at javax.validation.Validation$DefaultValidationProviderResolver.getValidationProviders(Validation.java:209)
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:173)
    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:50)
    at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:299)
    at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:82)
    ... 44 more
Caused by: java.lang.ClassNotFoundException: org.apache.geronimo.osgi.locator.ProviderLocator
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 49 more

我的代码遵循 模态

package com.prac.core.modal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "Stock")
public class Stock {

    @Id
    @GeneratedValue
    @Column(name = "Stock_Id")
    private Integer stockId;

    @Column(name = "Stock_Code")
    private String stockCode;

    @Column(name = "Stock_Name")
    private String stockName;

    public Integer getStockId() {
        return stockId;
    }

    public void setStockId(Integer stockId) {
        this.stockId = stockId;
    }

    public String getStockCode() {
        return stockCode;
    }

    public void setStockCode(String stockCode) {
        this.stockCode = stockCode;
    }

    public String getStockName() {
        return stockName;
    }

    public void setStockName(String stockName) {
        this.stockName = stockName;
    }

    @Override
    public String toString() {
        return "Stock [StockId =" + stockId + ", stockCode =" + stockCode + ", stockName =" + stockName + "]";
    }
}

package com.prac.core.dao;

import java.util.List;

import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.prac.core.modal.Stock;

@Repository
@Transactional(propagation = Propagation.REQUIRED)
public class StockDao {

        @PersistenceContext
        private EntityManager entityManager;

        public EntityManager getEntityManager() {
            return entityManager;
        }

        public void setEntityManager(EntityManager entityManager) {
            this.entityManager = entityManager;
        }

        public void insert(Stock stock) {
            entityManager.persist(stock);
        }

        public List<Stock> getAllList() {
            Query query = entityManager.createQuery("SELECT S FROM Stock S");
            List<Stock> sto = (List<Stock>)query.getResultList();
            return sto;
        }
}

服务

package com.prac.core;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.prac.core.dao.StockDao;
import com.prac.core.modal.Stock;

@Component
public class StockService {

    @Autowired
    private StockDao stockDao;

    public void addStock(Stock stock) {
        stockDao.insert(stock);
    }

    public List<Stock> getAllStock() {
        return stockDao.getAllList();
    }
}

数据库比例

jpa.jdbc.driverClassName = com.mysql.jdbc.Driver
jpa.jdbc.url = jdbc:mysql:// localhost:3306 /
prac jpa.jdbc.username = root
jpa.jdbc.password = *

apppersistence.xml

<?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="modalUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>com.prac.core.modal.Stock</class>
        <properties> 
            <property name="javax.persistence.validation.mode" value="none" />
            <!-- <property name="hibernate.validator.apply_to_ddl" value="false"/>
            <property name="hibernate.validator.autoregister_listeners" value="false"/> -->
            <property name="driverClassName" value="${jpa.jdbc.driverClassName}" />
            <property name="url" value="${jpa.jdbc.url}" />
            <property name="username" value="${jpa.jdbc.username}" />
            <property name="password" value="${jpa.jdbc.password}" />
           <!--  NONE
            </property>   -->
        </properties>  
    </persistence-unit>
</persistence>

app-config.xml

<?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:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                           http://www.springframework.org/schema/util
                           http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <!-- enabling annotation driven configuration / -->
    <context:annotation-config />
    <context:component-scan base-package="com.prac" />

    <context:property-placeholder location="classpath:database.properties" />

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
        p:entity-manager-factory-ref="entityManagerFactory">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaDialect" ref="jpaDialect" />
    </bean>

    <!-- Enable the transaction annotations, by this declarative transactions 
        can be used -->
    <tx:annotation-driven transaction-manager="transactionManager" />
    <!-- ==================== Data source definitions ==================== -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jpa.jdbc.driverClassName}" />
        <property name="url" value="${jpa.jdbc.url}" />
        <property name="username" value="${jpa.jdbc.username}" />
        <property name="password" value="${jpa.jdbc.password}" />
    </bean>
    <!-- ==================== Hibernate Entity Manager ==================== -->

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/apppersistence.xml" />
        <property name="persistenceUnitName" value="modalUnit" />
        <property name="jpaDialect" ref="jpaDialect" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
                <!-- <property name="validation.mode" value="NONE" />  -->
            </bean>
        </property>
    </bean>

    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</beans>

pom.xml

<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 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.prac.core</groupId>
  <artifactId>SpringHibJPAEx</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>SpringHibJPAEx</name>
  <url>http://maven.apache.org</url>

  <properties>
    <!-- <spring.version>4.1.4.RELEASE</spring.version> -->
    <spring.version>3.0.7.RELEASE</spring.version>
    <hib.version>3.5.2-Final</hib.version>
    <hibjpa.version>1.0.1.Final</hibjpa.version>
  </properties>

  <dependencies>        
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>        
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</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-aop</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-expression</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-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>        
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.1</version>
    </dependency>       
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
    </dependency>       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hib.version}</version>
    </dependency>       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>${hib.version}</version>
    </dependency>       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.2.0.Final</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>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>       
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>     
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>3.5.2</version>
    </dependency>       
    <dependency>
        <groupId>aopalliance</groupId>
        <artifactId>aopalliance</artifactId>
        <version>1.0</version>
    </dependency>       
    <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.19.0-GA</version>
    </dependency>       
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>       
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0-6</version>
    </dependency>       
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.10</version>
    </dependency>       
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.10</version>
    </dependency>    
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
        <scope>provided</scope>
    </dependency>       
    <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-c3p0</artifactId>
         <version>3.6.10.Final</version>
         <scope>provided</scope>
      </dependency>    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.1.0.Final</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>     
</project>

MainMethod类-App

package com.prac.core;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.prac.core.modal.Stock;

public class App 
{
    public static void main( String[] args )
    {
        try {
            //System.out.println( "Hello World!" );
            System.out.println("************** BEGINNING PROGRAM **************");
            ApplicationContext context = new ClassPathXmlApplicationContext("app-config.xml");
            StockService stockService = (StockService) context.getBean("stockService");

            Stock stock = new Stock();
            stock.setStockCode("A1");
            stock.setStockName("Amar");

            stockService.addStock(stock);
            System.out.println("Stock : " + stock + " added successfully");

            List<Stock> stockList = stockService.getAllStock();
            System.out.println("The list of all Stock = " + stockList);

            System.out.println("************** ENDING PROGRAM *****************");
        } catch(Exception e) {
            System.out.println("*********************** ERROR ****************************");
            e.printStackTrace();
        }
    }
}

阅读 251

收藏
2020-11-30

共1个答案

小编典典

添加geronimo-osgi-locator以添加缺少的类文件。似乎tomcat和其他应用程序服务器也附带了与它们的应用程序服务器打包在一起的那些类。

第209行的javax.validation.Validation.java访问在第38行中导入的ProviderLocator。

javax.validation.Validation.java

import org.apache.geronimo.osgi.locator.ProviderLocator; List serviceProviders = ProviderLocator.getServices(ValidationProvider.class.getName(), this.getClass(), cl);

Maven依赖关系:

    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-osgi-locator</artifactId>
        <version>1.1</version>
    </dependency>
2020-11-30