加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – Spring Boot中Spring Security的XML配置

发布时间:2020-12-15 01:43:37 所属栏目:大数据 来源:网络整理
导读:我想将基于XML的配置用于Spring Security.第一个想法是使用SHA-256或任何其他散列函数用于用户密码.我找不到用普通java解决这个问题的好方法.所以我开始在xml中配置东西.当它开始变得有趣时,这就是重点. 我的配置: spring-boot 1.1.8.RELEASE spring-boot-s

我想将基于XML的配置用于Spring Security.第一个想法是使用SHA-256或任何其他散列函数用于用户密码.我找不到用普通java解决这个问题的好方法.所以我开始在xml中配置东西.当它开始变得有趣时,这就是重点.

我的配置:

> spring-boot 1.1.8.RELEASE
> spring-boot-starter- * 1.1.8
> tomcat-embed-jasper:8.0.8

弹簧security.xml文件:


我在类中加载xml文件,其中可以找到public static void main:

@Configuration
@ComponentScan
@EnableAutoConfiguration
@Order(HIGHEST_PRECEDENCE)
@ImportResource({
        "/spring-security.xml"
})
public class PhrobeBootApplication extends SpringBootServletInitializer {
...
}

但是我在任何pageload上都得到以下异常:

[ERROR] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext 
...

所以看起来资源/ WEB-INF / web.xml的配置没有加载,如果我有一个好的understanding from the documentation,我应该在使用普通弹簧时使用它,没有启动. (应配置过滤器).我对吗?

为什么会发生这种错误?有没有更好的方法在spring-boot中使用基于xml的配置来实现spring-security? web.xml甚至可以通过tomcat加载吗?

最佳答案
我遇到了同样的问题,然后我改变了XML文件的路径,并将其保存在src / main / resources / spring中.它工作正常.

@SpringBootApplication

@ImportResource("classpath:/spring/spring-security.xml")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读