我有一个 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/