在Struts2中创建hibernate配置实例的实例时抛出Servlet服务错误。这是我得到的错误。当创建org.hibernate.cfg.Configuration
包中存在的配置类实例时,将显示以下错误,并且无法解析。
Dec 18, 2015 4:42:57 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not found
at java.util.ServiceLoader.fail(ServiceLoader.java:214)
at java.util.ServiceLoader.access$400(ServiceLoader.java:164)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:350)
at java.util.ServiceLoader$1.next(ServiceLoader.java:421)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:324)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:40)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:213)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:119)
at hibernateTest.HibernateTestController.<init>(HibernateTestController.java:95)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:158)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:189)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
at com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
...
任何建议都非常感谢并提前感谢。
答案 0 :(得分:0)
当hibernate.cfg.xml
不在正确的路径中时,它发生在我身上。
hibernate.cfg.xml
文件添加到类路径中。(您可以将其放入&#39; resources&#39;文件夹。)如果hibernate.cfg.xml
已经在类路径中,请尝试将文件名作为参数传递给配置。
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
如果要为hibernate.cfg.xml
文件使用其他路径,请执行以下操作。
String hibernatePropsFilePath = "/etc/configs/hibernate.cfg.xml";
File hibernatePropsFile = new File(hibernatePropsFilePath);
Configuration configuration = new Configuration();
configuration.configure(hibernatePropsFile);
希望这有帮助。