spring - 是 8.5.5.2 : No spring webapplicationinitializer types detected on classpath

标签 spring spring-mvc websphere-8

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

我为该项目构建了一场 war ,并使用管理控制台将其部署在 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";

    }

}

提前致谢 :)

最佳答案

只是分享我的案例,可能会对您有所帮助。
我也将带有 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

关于spring - 是 8.5.5.2 : No spring webapplicationinitializer types detected on classpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961048/

相关文章:

java - 我需要我的 Spring Boot Web 应用程序在 JUnit 中重新启动

java - Spring boot应用程序-Tomcat部署-无法确定合适的驱动程序类

java - EJB 3.1 绑定(bind)在 Websphere Application Server 上不起作用

java - Websphere liberty 配置文件错误 : 404 SRVE0190E

java - Websphere 8.5.5.7 与 Java7 : existing profiles are not starting

Spring REST - 必须至少有一个 RequestParameter

java - Spring @Inject 服务类返回空指针异常

java - 使用从 Spring Controller 获取的值填充表单

java - 如何在Spring Boot应用程序中添加方法级别身份验证?

java - Spring 安全 : Multiple HTTP Config not working