springsecurity maven 打包后,404错误。maven 打包后,加载内置的xml文件
作者:互联网
404错误,解决的办法,主要是pom文件
<build> <resources> <resource> <directory>src/main/resources</directory> <!--包含antisamy.xml--> <includes> <!-- <include>**/*.properties</include>--> <!-- <include>**/*.xml</include>--> <!-- <include>**/*.yml</include>--> <include>**/**</include> </includes> <filtering>false</filtering> </resource> <!--这段解决maven package后,找不到页面,404 错误--> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.2.0</version> <configuration> <encoding>UTF-8</encoding> <useDefaultDelimiters>true</useDefaultDelimiters> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- <version>2.4.1</version>--> <version>1.4.2.RELEASE</version> <configuration> <fork>true</fork> <addResources>true</addResources> <mainClass>cn.taotao.WarehouseApplication</mainClass> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
加载内置的xml文件
antisamy-tralin.xml 文件在resources目录下,打jar包后,需要得到他的url,然后从url读取到目标中。
public class XssRequestWrapper extends HttpServletRequestWrapper { //获得antisamy框架所需的决策文件路径 private static URL antisayPath = XssRequestWrapper.class.getClassLoader().getResource("antisamy-tralin.xml"); public XssRequestWrapper(HttpServletRequest request) { super(request); } public static Policy policy = null; static { try { //过滤策略对象 policy = Policy.getInstance(antisayPath); } catch (PolicyException e) { e.printStackTrace(); } }
错误的代码,如下,这里得不到file,如果需要得到file,用上面的方法,File file = new File(url); 构建一个。
String file = XssRequestWrapper.class.getClassLoader().getResource("antisamy-tralin.xml").getFile();
标签:xml,--,antisamy,maven,打包,org,resources 来源: https://www.cnblogs.com/sdgtxuyong/p/16504277.html