java - Tomcat Web 应用程序适用于 Windows 而不是 Linux

标签 java linux spring maven tomcat

我有一个 maven/spring-mvc 应用程序,它是一个非常简单的 Web 应用程序,它调用 mvc Controller ,后者调用 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 实例上?

最佳答案

我解决了这个问题。

我声明 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 片段不需要更改

<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 却给了我一个问题。 如果有人愿意解释,那就太好了。

关于java - Tomcat Web 应用程序适用于 Windows 而不是 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24648245/

相关文章:

java - 如何使 Content-Type header 可选?

java - Spring Tool Suite 3.6.2 无法添加服务器适配器 Oracle Weblogic Server 10.3.5

java - 使用扫描仪分割字符串时出现问题

JAVA-11: java.net.httpClient 如何设置重试?

c++ - readdir() 显示不可见文件

linux - 如何将批处理模式作业分发到运行通过 NFS 安装的 Linux 的各个板

linux - iptables 删除与 postgres 的输入连接

java - "mvn spring-boot:run"与 "java jar target/xxx.jar"

java - 我如何在 JTabbedPane 的选项卡中添加 JScrollPane

java - 在不同的 View 中更改 TextView