1. 程式人生 > >web tomcat 7可以執行,部署weblogic10.3不行

web tomcat 7可以執行,部署weblogic10.3不行

工程 :mave ,mybits,spring spring mvc restful

專案在tomcat 下正常執行,而在weblogic各種錯誤:

1)首先出現的 ,打成war 上傳到weblogic 伺服器,啟動weblogic 也正常,視乎一切都很順利,在瀏覽器很愉快的敲響首頁的訪問地址(敲回車特用力),尼瑪,一點反應都有,沒有404 沒有500 更沒有503....吐血之旅就這樣開始了,查看了AdminServer下log, 貌似只說找不到這個URL 處理類,很平常,一點異常都木有,往往看似平常,最後最難下手,google下,組嘗試了下 下面的做法,竟然部署上去了

然後檢視web.xml,發現如下配置

  <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:applicationContext*.xml</param-value> 
  </context-param>

將其改為

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath:applicationContext.xml,classpath:applicationContext-myBatis.xml</param-value> 
  </context-param>


2) 緊接著,馬上給你拋個異常,這回比什麼資訊都木有好多,起碼見紅了,興奮無比,在去見google,說包衝突,幸虧這次工程用maven,去掉某些包,容易

java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parser.DocumentBuilderFactroy

      原因:war包中的xml-apis-xx.jar和weblogic中的xml解析包出現衝突;

      解決辦法:從專案中刪掉這個jar包,如果是在maven情況下,可以採用maven的方式去掉,比如這個包是引入dom4j時傳遞引入的包,則可致在依賴中新增exclusion標籤去掉

                          對該jar包的依賴;

maven 打包去掉某些jar

<packagingExcludes>
<!-- WEB-INF/classes/com/thinkgem/jeesite/** -->
WEB-INF/classes/org/apache/ibatis/**,
WEB-INF/classes/org/mybatis/spring/**,
WEB-INF/lib/xml-apis-*.jar

</packagingExcludes>

或者包scope改下

   * compile,預設值,適用於所有階段,會隨著專案一起釋出。
    * provided,類似compile,期望JDK、容器或使用者會提供這個依賴。如servlet.jar。
    * runtime,只在執行時使用,如JDBC驅動,適用執行和測試階段。
    * test,只在測試時使用,用於編譯和執行測試程式碼。不會隨專案釋出。
    * system,類似provided,需要顯式提供包含依賴的jar,Maven不會在Repository中查詢它。 

3) 搞定上面那個後,新的異常 接踵而至,org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.ClassCastException: weblogic.xml.stax.XMLStreamInputFactory cannot be cast to javax.xml.stream.XMLInputFactory
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      解決方法 https://community.oracle.com/thread/847969?start=0&tstart=0

weblogic-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
<!-- prefer-application-packages -->
<package-name>javax.xml.ws.*</package-name>
<package-name>javax.xml.bind.*</package-name>
<package-name>javax.jws.*</package-name>
<package-name>javax.namespace.xml.*</package-name>
<package-name>javax.xml.soap.*</package-name>
<package-name>org.apache.xerces.*</package-name>
<package-name>org.apache.commons.*</package-name>
<package-name>com.sun.xml.*</package-name>
<package-name>org.hibernate.*</package-name>    


<container-descriptor>
     <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor> 
    <charset-params>
        <input-charset>
            <resource-path>/*</resource-path>
            <java-charset-name>UTF-8</java-charset-name>
        </input-charset>
    </charset-params>
    <jsp-descriptor>
        <encoding>UTF-8</encoding>
    </jsp-descriptor>
    <context-root>/netManage</context-root>
    <session-descriptor>
        <timeout-secs>1800</timeout-secs>
    </session-descriptor>
    <weblogic-version>10.3</weblogic-version>
</weblogic-application>

4)程式終於可以跑起來,查詢沒問題,介面很美麗,很爽,可是當保持下,又來異常了

 Handler processing failed; nested exception is java.lang.AbstractMethodError
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1280)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:958)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.AbstractMethodError
at javax.persistence.Persistence$1.isLoaded(Persistence.java:78)
at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56)
at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:130)
at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation.isReachable(CachingTraversableResolverForSingleValidation.java:46)
at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1358)
at org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1343)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:520)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:465)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:429)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:381)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:184)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:207)
at com.thinkgem.jeesite.common.beanvalidator.BeanValidators.validateWithException(BeanValidators.java:38)
at com.thinkgem.jeesite.common.web.BaseController.beanValidator(BaseController.java:77)
at com.thinkgem.jeesite.modules.sys.web.UserController.save(UserController.java:115)
at com.thinkgem.jeesite.modules.sys.web.UserController$$FastClassBySpringCGLIB$$25977f0a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor$1.proceed(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:82)
at org.apache.shiro.authz.aop.AuthorizingMethodInterceptor.invoke(AuthorizingMethodInterceptor.java:39)
at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor.invoke(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:115)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
at com.thinkgem.jeesite.modules.sys.web.UserController$$EnhancerBySpringCGLIB$$88b85748.save(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
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:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
... 43 more
(String)

weblogic 中使用hibernate validator

      使用hibernate validator,在tomcat下部署沒有問題,釋出到weblogic(10)下面就報錯了。在使用驗證時有以下錯誤: java.lang.AbstractMethodError: getProviderUtil at javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Unknown Source)       出錯原因是weblogic自身帶有openjpa的包(hibernate、openjpa掐架?),解決方法是在spring中增加配置 dispatcher-servlet.xml <mvc:annotation-driven validator="validator"/> applicationContext.xml <bean name="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="traversableResolver"> <bean class="com.....ExtTraversableResolver"></bean> </property> </bean> 其中ExtTraversableResolver程式碼如下: import java.lang.annotation.ElementType; import javax.validation.Path; import javax.validation.TraversableResolver; public class ExtTraversableResolver implements TraversableResolver { public final boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) { return true; } public final boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) { return true; } }

大功告成