0

我正在尝试使用 vFabric tc Server 在 Spring Tool Suite (STS) 中部署我的 Web 应用程序,但出现异常。值得注意的是,如果我在独立的 Tomcat 6 中编译和运行,它运行良好。我尝试了 vFabric tc 版本的 tomcat-7.0.35.B.RELEASE 和 tomcat-6.0.36.B.RELEASE。

错误是:

java.lang.IllegalArgumentException: class [springapp.web.spring.MyInitializer] must implement ApplicationContextInitializerclass springapp.web.spring.MyInitializer is not assignable to interface org.springframework.context.ApplicationContextInitializer

我无法解释为什么在初始化程序确实实现时会发生此错误ApplicationContextInitializer

public class MyInitializer implements ApplicationContextInitializer {
  public void initialize(ConfigurableApplicationContext ctx) {
    try {
        PropertySource ps = new ResourcePropertySource("file:///home/jim/development/act/impact/webapp.properties");
        ctx.getEnvironment().getPropertySources().addFirst(ps);
        // perform any other initialization of the context ...
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
  }
}

有没有人对我可以尝试让它运行有什么建议?

4

2 回答 2

2

您的应用程序服务器上有不同版本的org.springframework.context.ApplicationContextInitializer类(在spring-contextjar 中)。这通常是由于将 jar 放入胖战争和应用程序服务器自己的类路径中造成的。通常,您应该避免在系统类路径中包含系统 API(如 Servlet)之外的任何内容,并在每个应用程序中包含必要的 jar。

于 2013-11-15T11:49:57.643 回答
0

我不明白为什么会这样,但问题出在我的 pom 文件spring-context-support中:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-suppoer</artifactId>
    <version>3.2.2.RELEASE</version>
    <type>pom</type>
</dependency>

删除type元素解决了这个问题。

于 2013-11-15T13:32:08.660 回答