2016-03-05 91 views
0

我想運行一個用Java編寫的項目,並在Linux上使用Spring框架來擴展某些功能。該項目最初是在Windows平臺上開發的,但是,我試圖在Ubuntu 15.10上運行(並繼續工作)。該平臺是Tomcat 8.0.30,PostgreSQL 9.4,JDK 1.8.0_73,Spring 4.2.0。項目是在Spring Tool Suite下使用Gradle 2.5構建的。除了必要的路徑之外,所有內容大部分都在默認配置下。在java中的後端是一個REST服務,我甚至還沒有開始通過代碼。相同的java代碼不能在不同的機器上運行

問題是,整個事情無法運行在這個特定的機器上(我會稱之爲桌面)。構建是成功的,一切都很好,直到戰爭部署在tomcat上。根據具體情況,在這臺機器上,部署將產生一個Oauth bean實例化的Spring循環引用,或者將正常傳遞,直到來自前端的第一個請求(即登錄),並且它會產生堆棧溢出錯誤,一遍又一遍(開始時沒有其他可能的請求)。

如果在幾個不同的機器上完全相同的設置完全相同的代碼沒有小故障,這並不奇怪。我曾嘗試是:

  • 的Ubuntu 12.04,相同的Java,年長的PostgreSQL(9.1我認爲) - 適用於第一次部署
  • MacOS的,最新版本的Java,最新的PostgreSQL - 適用於第一次部署
  • 的Ubuntu 12.04 (其他),同樣的Java,年長的PostgreSQL - 適用於第一次部署
  • 的Windows 7 64位系統,同樣的設置,在Linux上的PostgreSQL - 適用於第一次部署

要擴大一點,我最近升級了桌面,事先它正在運行除了我設法通過創建一個新用戶在桌面上實際運行項目並在其下運行之外,它還具有完全相同的效果。之後,它在我的常規用戶下工作,但只能在STS下運行,部署在外部tomcat 8.0.30上。如果在STS附帶的Pivotal TC服務器下運行,我會得到相同的錯誤。如果手動部署war到tomcat 8.0.30,再次出現錯誤。這些「黑客」不再適用於新版本。

我也嘗試從運行在其他機器上的前端查詢項目,結果是一樣的,所以它純粹是關於Java和/或Tomcat的東西。我也嘗試dockerize tomcat(最新的8.0.32標記,openjdk-8,還有1.8.0_73),但沒有運氣。將在筆記本電腦上工作的編譯過的戰爭轉移到桌面上 - 再次沒有帶來積極的結果。

這是日誌的一部分:

05-Mar-2016 02:21:32.868 SEVERE [http-nio-8080-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/backend] threw exception [Filter execution threw an exception] with root cause 
java.lang.StackOverflowError 
at org.springframework.beans.factory.support.AbstractBeanFactory.transformedBeanName(AbstractBeanFactory.java:1084) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:238) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) 
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
at com.sun.proxy.$Proxy100.loadClientByClientId(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) 

...它的推移和

的當前狀態是:建立清潔,部署是乾淨的,總是給從錯誤登錄。

我還不熟悉Spring,所以我無法從日誌中找出任何有用的東西。不過,我確信,服務安裝正確,並且正在運行。環境儘可能配置爲接近默認值,以消除差異。

任何提示或輸入什麼可能是原因(和解決方案),將不勝感激。我會盡力提供任何可能有用的信息。

謝謝!

+0

向我們展示loadClientByClientId方法 –

+0

另外,如果您設置日誌記錄爲org.springframework的調試,那麼看看有什麼不同,當它工作,當它不。 –

+0

如果另一方面,應用程序運行平穩呃操作系統,那麼它最有可能與內存分配問題。嘗試使用-Xms和-Xmx選項增加JVM內存。 – Ayman

回答

2

好,在這樣的意見,非常有用的東西,但回顧一下......

要解決這個問題,這是非常有用的,我知道這個問題是不是與代碼相關的,但它是一個已知的(雖然很少見)問題。確切地說,初始化的順序是罪魁禍首,並試圖訪問尚未初始化的對象(其中創建代理對象)。

我的解決方案是不時尚,而且很可能不是由這本書,但它確實解決這個問題對我來說。我不是依賴@Autowired和代理,而是爲每個麻煩的類創建單例,從而確保配置正確設置,並且在第一次請求時可以使用該對象 - 無論它來自何處。

在評論的鏈接包含有關該問題的性質更詳細的解釋。感謝大家的幫助!

PS。某處,而試圖找到一個解決這個問題(和下面的鏈接),我也遇到了關於「AnnotationConfigWebApplicationContext後 - 異常上下文初始化過程中遇到 - 取消刷新嘗試 org.springframework.beans.factory.BeanCreationException:錯誤創建豆名爲「oauth2TokenController」:自動裝配依賴注入失敗;嵌套的例外是org.springframework.beans.factory.BeanCreationException:無法自動裝配領域:......如此下去..錯誤名爲「創造豆可能會在同一個可解但是,還沒有嘗試過

相關問題