我想将基于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
ecurity"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd>
ecurity="none"/>
ecurity="none"/>
login-page='/login.html'/>
我在类中加载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")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。