【问题标题】:WAS 8.5.5.2 : No spring webapplicationinitializer types detected on classpathWAS 8.5.5.2:在类路径上未检测到 spring webapplicationinitializer 类型
【发布时间】:2018-11-30 08:15:53
【问题描述】:

我有一个 spring mvc 项目。我正在尝试在 IBM Websphere 8.5.5.2 上部署这个项目

我已经为项目构建了一个战争,并使用管理控制台将其部署在 Websphere 上

我正在使用基于 Java 的配置。 我正在使用 AbstractAnnotationConfigDispatcherServletInitializer 和 WebMvcConfigurerAdapter 类进行配置。

但是当我部署应用程序时,我会根据控制台得到以下信息: 在类路径中未检测到 spring Webapplicationinitializer 类型

并且没有触发spring初始化。

我的代码如下

@EnableWebMvc
@Configuration
@ComponentScan({ "com.demo" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/jsp/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

}

public class MyWebInitializer extends
        AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] { };
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { SpringWebConfig.class };
    }

}

@Controller
public class HelloController {

    @RequestMapping(value = "/qwerty", method = RequestMethod.GET)
    public String printWelcome() {

        return "qwerty";

    }

}

提前谢谢:)

【问题讨论】:

  • 你有日志可以看到 Spring 初始化吗?甚至将 Spring 日志记录设置为 DEBUG 级别?这对我过去调试类似问题有所帮助。
  • 是的,调试级别已经设置好了。但是调度器 servlet 根本没有被触发,因为没有检测到 webApplicationInitializer
  • 是否记录了任何主要的 Spring 初始化?
  • 没有。没有记录与 Spring 初始化相关的任何内容
  • 希望我能提供更多帮助,但我自己还没有尝试过。听起来有些可能的原因通常不是特定于 WebSphere,是 Spring 的多个副本和缺少依赖项(例如 slf4j)。 stefan-isele.logdown.com/posts/201646 祝你好运,希望比我更了解的人会出现。

标签: spring spring-mvc websphere-8


【解决方案1】:

只是为了分享我的案例,可能对你有帮助。

我也部署了带有 JSP 的 springmvc servlet 作为 IBM WAS 8.5 的前端。 我从服务器获得了相同的调试信息,但它不影响性能。

我在 servlet.xml 中的 internalViewResolver 和 resourceHandler 设置仍然有效。

[21/4/21 11:11:38:003 SGT] 000000a4 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [BP13BWDbPocWeb_war#BP13BWDbPocWeb.war]:.No Spring WebApplicationInitializer types detected on classpath
[21/4/21 11:11:38:015 SGT] 000000a4 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [BP13BWDbPocWeb_war#BP13BWDbPocWeb.war]:.Initializing Spring root WebApplicationContext
[21/4/21 11:11:38:016 SGT] 000000a4 ContextLoader I org.springframework.web.context.ContextLoader initWebApplicationContext Root WebApplicationContext: initialization started

【讨论】:

    【解决方案2】:

    我的猜测,我没有尝试过,是你依赖 @Configuration 和 @ComponentScan({ "com.demo" }) 让您的 Spring 应用程序扫描注释。当您将应用程序作为 war 文件运行时,这不会神奇地发生。

    具体来说,从下面的文档中,您缺少一个 SpringBootServletInitializer,它定义了一个配置方法来告诉支持容器它需要扫描哪些类以查找注释:

    https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file

    HTH

    【讨论】:

    • 我使用的是 Spring 而不是 Spring Boot。所以我不能使用 SpringBootServletInitializer
    • 你找到解决办法了吗??
    猜你喜欢
    • 2013-04-25
    • 2014-05-21
    • 2016-06-19
    • 2014-08-28
    • 2019-09-06
    • 2017-06-02
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多