spring boot,struts2,security tags集成

一、maven包的引用

struts2 maven引入:

<dependency>
		    <groupId>org.apache.struts</groupId>
		    <artifactId>struts2-core</artifactId>
		    <exclusions>
		        <exclusion>
		            <groupId>asm</groupId>
		            <artifactId>asm</artifactId>
		        </exclusion>
		        <exclusion>
		            <groupId>asm</groupId>
		            <artifactId>asm-commons</artifactId>
		        </exclusion>
		    </exclusions>
		</dependency>
		<dependency>
		    <groupId>org.apache.struts</groupId>
		    <artifactId>struts2-spring-plugin</artifactId>
 		    <exclusions> 
 				<exclusion> 
 					<groupId>org.springframework</groupId> 
					<artifactId>spring-beans</artifactId> 
 				</exclusion> 
 				<exclusion> 
 					<groupId>org.springframework</groupId> 
 					<artifactId>spring-core</artifactId> 
 				</exclusion> 
 				<exclusion> 
 					<groupId>org.springframework</groupId> 
					<artifactId>spring-context</artifactId> 
 				</exclusion> 
 				<exclusion> 
					<groupId>org.springframework</groupId> 
 					<artifactId>spring-expression</artifactId> 
   				</exclusion> 
				<exclusion> 
					<groupId>org.springframework</groupId> 
 					<artifactId>spring-aop</artifactId> 
				</exclusion> 
				<exclusion> 
					<groupId>org.springframework</groupId> 
					<artifactId>spring-web</artifactId> 
				</exclusion> 
				<exclusion> 
					<groupId>org.springframework</groupId> 
					<artifactId>spring-webmvc</artifactId> 
				</exclusion> 
				<exclusion> 
 					<groupId>org.springframework</groupId> 
					<artifactId>spring-jcl</artifactId> 
				</exclusion> 
			</exclusions> 
		</dependency>
		<dependency>
		    <groupId>org.apache.struts</groupId>
		    <artifactId>struts2-convention-plugin</artifactId>
		</dependency>
		<dependency>
		    <groupId>org.apache.struts</groupId>
		    <artifactId>struts2-json-plugin</artifactId>
		</dependency>
		<dependency>
		    <groupId>org.apache.commons</groupId>
		    <artifactId>commons-jci-core</artifactId>
		</dependency>

spring maven包引入:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-autoconfigure-processor</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-configuration-metadata</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
</dependency>		
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-webmvc</artifactId>
  </dependency>
<dependency>
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-framework-bom</artifactId>
	<scope>import</scope>
	<type>pom</type>
</dependency>
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jsp-api</artifactId>
</dependency>
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
	<groupId>org.yaml</groupId>
	<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
		<groupId>org.jasypt</groupId>
		<artifactId>jasypt</artifactId>
</dependency>
<dependency>
	<groupId>com.thoughtworks.xstream</groupId>
	<artifactId>xstream</artifactId>
</dependency>
<dependency>
	<groupId>org.bouncycastle</groupId>
	<artifactId>bcprov-jdk15on</artifactId>
</dependency>

二、spring security Filter配置

在spring boot入口类中添加下面两个方法,主要是用来添加springSecurityFilterChain和JspSupportServlet:

springSecurityFilterChain:security设置filter。

JspSupportServlet:struts2读取security tag标签设置。

@SuppressWarnings({"rawtypes", "unchecked" })
    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        StrutsPrepareAndExecuteFilter struts = new StrutsPrepareAndExecuteFilter();
        registrationBean.setFilter(new DelegatingFilterProxy("springSecurityFilterChain"));
        registrationBean.setFilter(struts);
        registrationBean.setOrder(1);
        return registrationBean;
    }
    
    @SuppressWarnings({"rawtypes", "unchecked" })
    @Bean
    public ServletRegistrationBean servletRegistrationBean(){
         ServletRegistrationBean registrationBean = new ServletRegistrationBean();
         registrationBean.setName("JspSupportServlet");
         registrationBean.setServlet(new JspSupportServlet());
         registrationBean.addUrlMappings("/JspSupportServlet");
         registrationBean.setLoadOnStartup(1);
         return registrationBean;
     }

这里需要注意一点:registrationBean.addUrlMappings("/JspSupportServlet");不添加这句代码的话,如果项目静态资源设置正确的话,会访问不了静态资源,会提示如下错误:

HTTP Status 405 - HTTP method GET is not supported by this URL

三、静态资源设置

注意:文章到这里还没有完,由于篇幅限制,完整内容请到hongfu951博客上查看

完整内容URL地址:spring boot集成struts2引用security标签tags

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幻想多巴胺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值