Spring Filter中的AbstractMethodError org.hibernate.ejb.HibernatePersistence.getProviderUtil()Ljavax / persistence / spi / ProviderUtil;

前端之家收集整理的这篇文章主要介绍了Spring Filter中的AbstractMethodError org.hibernate.ejb.HibernatePersistence.getProviderUtil()Ljavax / persistence / spi / ProviderUtil;前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个基于Spring Web模型 – 视图 – 控制器(MVC)框架的项目. Spring Web模型 – 视图 – 控制器(MVC)框架的版本是3.2.8.

我用这个方法实现了一个过滤器:

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws ServletException,IOException {

        HttpServletRequest httpServletRequest;
        ThreadContext threadContext;

        //String path = ((HttpServletRequest) request).getRequestURI();

        if (request instanceof HttpServletRequest) {
            httpServletRequest = (HttpServletRequest) request;
            threadContext = ThreadContext.getInstance();

            try {

                DetailedUser ecasUser = (DetailedUser) httpServletRequest.getUserPrincipal();

                if (ecasUser != null) {
                    threadContext.setDomainUsername(ecasUser.getDomainUsername());
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            if (httpServletRequest.getRemoteUser()!=null) {         
                threadContext.setUserID(httpServletRequest.getRemoteUser());
            }
        }


        try {

            if (filterChain != null) {

                filterChain.doFilter(request,response);                

            }

        } catch (IOException e) {

            LOGGER.equals(e.getMessage());
        }    
    }

在这行filterChain.doFilter(request,response);我有这个奇怪的错误

] Root cause of ServletException.
ava.lang.AbstractMethodError: org.hibernate.ejb.HibernatePersistence.getProviderUtil()Ljavax/persistence/spi/ProviderUtil;
       at javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Persistence.java:110)
       at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:62)
       at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:94)
       at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
       at org.hibernate.validator.engine.ValidatorImpl.isCascaderequired(ValidatorImpl.java:783)
       at org.hibernate.validator.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:360)
       at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:216)
       at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
       at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:102)
       at org.springframework.validation.DataBinder.validate(DataBinder.java:772)
       at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.validateIfApplicable(ModelAttributeMethodProcessor.java:159)
       at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:107)
       at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
       at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157)
       at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124)
       at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
       at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
       at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
       at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
       at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
       at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
       at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
       at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
       at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
       at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
       at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
       at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
       at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
       at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
       at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
       at com.tdk.devices.support.context.DevicesSecurityFilter.doFilter(DevicesSecurityFilter.java:82)

这是导入的库:

   

它似乎与pom.xml文件的hibernate依赖关系有关

最佳答案
这个错误背后的原因是,Hibernate在构建PersistenceProviderResolver中返回类路径上所有PersistenceProviders的列表.由于Weblogic lib包含JPA 1.0,因此它返回JPA2.0以及JPA 1.0持久性提供程序.

要修复此错误,您可以使用以下方法.

创建一个HibernatePersistenceProviderResolver类作为

 public class HibernatePersistenceProviderResolver implements PersistenceProviderResolver {

private volatile PersistenceProvider persistenceProvider = new HibernatePersistence();

public List getPersistenceProviders() {
return Collections.singletonList(persistenceProvider);
}

public void clearCachedProviders() {
persistenceProvider = new HibernatePersistence();
}

public static void register() {
PersistenceProviderResolverHolder
.setPersistenceProviderResolver(new HibernatePersistenceProviderResolver());
}
}

添加一个监听器类来调用寄存器方法

public class HibernateContextListener implements ServletContextListener{

@Override
public void contextInitialized(ServletContextEvent sce) {
HibernatePersistenceProviderResolver.register();

}

@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub

}

}

在web.xml中添加侦听器条目

原文链接:https://www.f2er.com/spring/432081.html

猜你在找的Spring相关文章