首页 > 解决方案 > WAS 8.5.5.2:在类路径上未检测到 spring webapplicationinitializer 类型

问题描述

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

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

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

但是当我部署应用程序时,我根据控制台得到以下信息: no spring Webapplicationinitializer types detected on classpath

并且没有触发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";

    }

}

提前致谢 :)

标签: springspring-mvcwebsphere-8

解决方案


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

我也部署了带有 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

推荐阅读