当前位置: 代码迷 >> J2EE >> 创建SessionFactory是异常,大家帮小弟我看看
  详细解决方案

创建SessionFactory是异常,大家帮小弟我看看

热度:266   发布时间:2016-04-21 23:40:17.0
创建SessionFactory是错误,大家帮我看看
我以java application的方式运行下面这段代码的时候报错了,应该是配置文件applicationContext.xml有问题。但我在server(tomcat)中运行时可以顺利创建SessionFactory。高手们帮我看看是怎么回事,谢谢啦!

package com.fafu.oa.managers;

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

import com.fafu.oa.managers.InitSystemDatas;

public class InitSystemDatasTest {
public static ApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");

public static void main(String[] arg) {
System.out.println("before");
InitSystemDatas init = (InitSystemDatas)factory.getBean("initSystemDatas");
System.out.println("middle");
init.addOrUpdateInitDatas("init_data.xml");
System.out.println("after");
}

}


这是部分错误提示:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userManager': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Error applying BeanValidation relational constraints
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.fafu.oa.managers.InitSystemDatasTest.<clinit>(InitSystemDatasTest.java:9)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Error applying BeanValidation relational constraints
  相关解决方案