【问题标题】:Tomcat web application works on windows not on linuxTomcat Web 应用程序可以在 Windows 上运行,而不是在 linux 上运行
【发布时间】:2014-07-09 07:57:30
【问题描述】:

我有一个 maven/spring-mvc 应用程序,它是一个非常简单的 web 应用程序,它调用 mvc 控制器,它调用 web 服务来获取数据并将数据提供给 JSP。

我在 Eclipse 上的 Windows 机器上开发了这个应用程序。该应用程序执行得非常好。 我还通过命令提示符执行了“maven clean install”并创建了一个war文件并在windows上的tomcat 6和tomcat 7上手动部署,这也很好用。

现在我将同一个war文件移动到linux,它在catalina.out(tomcat日志)中给出了这个错误

`Caused by: org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: com.mondia.entertainment.ws.SecurityServer    
com.mondia.common.controller.HomeController.security; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No matching bean of type [com.mondia.entertainment.ws.SecurityServer] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for this dependency.    
Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}`

我的 mvc-dispatcher-servlet.xml 看起来像这样: `

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:application.properties" />
</bean>

<!-- enable @Autowired, @Required, @Resource (JSR-250) and other annotations -->
<context:annotation-config />
<context:component-scan base-package="com.mondia.entertainment" />
<context:component-scan base-package="com.mondia.common" />

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<jaxrs:client id="securityClient"
    serviceClass="com.mondia.entertainment.ws.SecurityServer" address="http://localhost:8080/restful-service/security">
    <jaxrs:features>
        <cxf:logging/>
    </jaxrs:features>
    </jaxrs:client>`

我什至将 apache-tomcat 7 文件夹(带有 war 文件)从 windows 移动到 linux 并尝试启动服务器,但我得到了同样的异常。

  1. 这个错误意味着什么?
  2. 为什么在我的 Windows 系统上的同一个 tomcat 实例上不会出现此错误?

【问题讨论】:

  • localhost:8080/restful-service/security 这个网址是否已启动并正在运行。如果失败,则可能永远不会创建 securityClient bean,因此会出现异常。
  • 是的,所有的 URL 都可以正常工作。

标签: java linux spring maven tomcat


【解决方案1】:

我解决了这个问题。

我声明 Autowired 变量的类,我需要使用 @DependsOn 注解声明它所依赖的 jaxrs 服务器。

@Controller
@RequestMapping("/content")
@DependsOn({"entertainmentClient", "securityClient"})
@SessionAttributes("clientAuthToken")
public class ContentController {

@Autowired
ContentServer entertainment;
@Autowired
SecurityServer security;

@RequestMapping("/home")
public ModelAndView someMethod(HttpSession session, @RequestHeader("User-Agent") String userAgent) {
    ModelAndView model = new ModelAndView("channel");
}
}

xml sn-p 但是不需要更改

<jaxrs:client id="entertainmentClient" serviceClass="com.mondia.entertainment.ws.ContentServer" address="http://rest.getmo.ae/restful-service/entertainment/">
</jaxrs:client>

好吧,我仍然不明白为什么 windows 上的 tomcat 在没有 @DependsOn 注释的情况下接受此代码,而 Linux 上的同一个 tomcat 给了我一个问题。 如果有人愿意解释,那就太好了。

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 2012-08-04
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多