尚硅谷 尚筹网项目后台管理系统的web.xml的替换
作者:互联网
因为web.xml的经常会验证(validating),动不动就卡住eclipse,因此决定把web.xml去掉
第一步在父项目中加入maven插件
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build>
第二步 创建几个配置类
RootConfig类代码
package com.atguigu; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource(locations= {"classpath:spring-persist-*.xml"}) public class RootConfig { }
WebConfig类代码
package com.atguigu; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource(locations= {"classpath:spring-web-mvc.xml"}) public class WebConfig { }
WebApplication类代码
package com.atguigu; import javax.servlet.Filter; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.DelegatingFilterProxy; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; public class WebApplication extends AbstractAnnotationConfigDispatcherServletInitializer{ @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{RootConfig.class}; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{WebConfig.class}; } @Override protected String[] getServletMappings() { return new String[] {"*.html","*.json"}; } @Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); return new Filter[] {characterEncodingFilter}; } }
第三步 把web.xml删除就行
后面做project clean 与maven update 操作就行了
标签:xml,web,尚筹网,springframework,org,import,new 来源: https://www.cnblogs.com/cplinux/p/12905521.html