【问题标题】:ApplicationContextInitializer related exception when deployed on vFabric tc Server in STS在 STS 中的 vFabric tc Server 上部署时与 ApplicationContextInitializer 相关的异常
【发布时间】:2013-11-15 11:42:54
【问题描述】:

我正在尝试使用 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();
    }
  }
}

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

【问题讨论】:

    标签: java spring tomcat spring-tool-suite


    【解决方案1】:

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

    【讨论】:

    • 我已经 grep 了 spring-context 的文件系统,在 vfabric lib 目录中没有任何迹象。过去使用 3.2.3 而不是 3.2.2 在 sts 中部署了其他几个项目,所以我删除了它们,但仍然没有乐趣。您对我如何进一步调试有什么建议吗?
    【解决方案2】:

    我不明白为什么会这样,但问题是在我的 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 元素解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2012-09-12
      • 2014-10-03
      • 1970-01-01
      • 2012-07-06
      • 2013-04-08
      • 2012-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多