相同的java代码不会在不同的机器上运行

相同的java代码不会在不同的机器上运行,java,spring,tomcat,Java,Spring,Tomcat,我试图在Linux上运行一个用Java编写并使用Spring框架的项目,以扩展一些功能。该项目最初是在Windows平台上开发的,但是,我正在尝试在Ubuntu 15.10上运行(并继续工作)。平台是Tomcat 8.0.30、PostgreSQL 9.4、JDK 1.8.0_73、Spring 4.2.0。该项目是在Spring工具套件下使用Gradle 2.5构建的。除必要的路径外,所有内容都处于默认配置下。java中的后端是一个REST服务,我甚至还没有开始阅读代码 问题是,整个程序无法在

我试图在Linux上运行一个用Java编写并使用Spring框架的项目,以扩展一些功能。该项目最初是在Windows平台上开发的,但是,我正在尝试在Ubuntu 15.10上运行(并继续工作)。平台是Tomcat 8.0.30、PostgreSQL 9.4、JDK 1.8.0_73、Spring 4.2.0。该项目是在Spring工具套件下使用Gradle 2.5构建的。除必要的路径外,所有内容都处于默认配置下。java中的后端是一个REST服务,我甚至还没有开始阅读代码

问题是,整个程序无法在这台特定的机器上运行(我称之为桌面)。构建成功,一切正常,直到战争部署到tomcat上。根据具体情况,在这台机器上,部署将在OAuthBean实例化上生成一个Spring循环引用,或者将正常传递,直到来自前端的第一个请求(即登录)为止,它将一次又一次地生成堆栈溢出错误(开始时不可能有其他请求)

如果在几台不同的机器上使用完全相同的代码和完全相同的设置,并且没有出现故障,那么这就不会那么奇怪了。我尝试的是:

  • Ubuntu12.04,同样的java,更老的postgresql(我想是9.1)——可以在第一次部署时使用
  • MacOS、最新java、最新postgresql-适用于第一次部署
  • Ubuntu12.04(其他),同样的java,较旧的postgresql-适用于第一次部署
  • Windows 7 x64,相同的设置,linux上的postgresql-适用于第一次部署
为了进一步扩展,我最近升级了桌面,之前它运行的是Ubuntu14.10,效果完全相同,只是我通过创建一个新用户在桌面上运行了这个项目,并在该用户下运行。之后,它在我的普通用户下工作,但只有在部署在外部Tomcat8.0.30上的STS下运行。如果在STS附带的关键TC服务器下运行,我会得到相同的错误。如果手动将war部署到tomcat 8.0.30,同样会出现错误。这些“黑客”不再适用于新版本

我还尝试从运行在其他机器上的前端查询项目,结果是一样的,因此这纯粹是关于Java和/或Tomcat的。我还尝试将tomcat(最新的8.0.32标签,使用openjdk-8,也使用1.8.0_73)dockerize,但没有成功。将在笔记本电脑上运行的编译好的war转移到台式机上,同样没有产生积极的效果

这是日志的一部分:

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,所以我无法从日志中看出任何有用的东西。不过,我可以肯定,这些服务安装正确,运行正常。环境的配置尽可能接近默认值,以消除差异

我们将非常感谢您提供任何有关这一问题的原因(和解决方案)的提示或意见。我会尽快提供可能有用的信息


谢谢大家!

好的,评论中有非常有用的东西,但要重述一下

为了解决这个问题,我知道这个问题与代码无关,但却是一个已知(尽管很少)的问题,这对我来说非常有用。确切地说,初始化的顺序是罪魁祸首,并试图访问尚未初始化的对象(然后在其中创建代理对象)

我的解决方案并不时尚,可能也不符合常规,但它确实为我解决了这个问题。我没有依赖@Autowired和proxies,而是为每个麻烦的类创建了单例,从而确保配置设置正确,并且对象在第一次请求时就可以使用——不管它来自哪里

评论中的链接包含关于问题性质的更详细解释。谢谢大家的帮助

在某个地方,当我试图找到这个问题的解决方案(并遵循链接)时,我还遇到了一篇关于“AnnotationConfigWebApplicationContext-上下文初始化期间遇到异常-取消刷新尝试”的帖子
org.springframework.beans.factory.BeanCreationException:创建名为“oauth2TokenController”的bean时出错:自动关联依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动关联字段:…它将继续..创建名为“的bean时出错可能以相同的方式解决,howev呃,我还没试过。

好的,所以,评论中有一些非常有用的东西,但要重述一下

为了解决这个问题,我知道这个问题与代码无关,但它是一个已知(尽管很少)的问题,这对我来说非常有用。确切地说,初始化的顺序是罪魁祸首,并且试图访问尚未初始化的对象(然后在其中创建代理对象)

我的解决方案并不时尚,也可能不是书上说的,但它确实为我解决了这个问题。我没有依赖@Autowired和proxies,而是为每个麻烦的类创建了单例,从而确保配置设置正确,并且对象在第一次请求时就可以使用——无论它来自何处

评论中的链接包含关于问题性质的更详细解释。谢谢大家的帮助

在某个地方,当我试图找到这个问题的解决方案(并遵循链接)时,我还遇到了一篇关于“AnnotationConfigWebApplicationContext-上下文初始化期间遇到异常-取消刷新尝试”的帖子 org.springframework.beans.factory.BeanCreationException:创建名为“oauth2TokenController”的bean时出错:自动关联依赖项的注入失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:Coul