【问题标题】:Reload users.properties at runtime spring在运行时重新加载 users.properties spring
【发布时间】:2016-05-24 01:43:23
【问题描述】:

我正在使用 Spring MVC 和 Spring Security 运行一个项目,并且我正在使用外部文件进行身份验证:

    <user-service id="userDetailsService" properties="users.properties"/>

但是当我更改属性文件时,我不得不重新启动服务器。所以,我想知道是否有一个解决方案,一个标签或参数,我可以放在标签“用户服务”上来指定重新加载缓存的超时时间。

感谢您的帮助

【问题讨论】:

    标签: java spring authentication spring-security properties


    【解决方案1】:

    您正在使用 InMemory Provider 并指定属性文件选项。 InMemory 提供程序不提供重新加载属性文件的选项。

    您可以移动到不同的提供程序,例如 daoAuthenticationProvider 以将用户存储在数据库中,或者实现您自己的 UserDetailsS​​ervice 以便它根据需要重新加载属性文件。

    您可以在此处找到 UserDetailService 的 JavaDoc: http://docs.spring.io/autorepo/docs/spring-security/4.0.3.RELEASE/apidocs/org/springframework/security/core/userdetails/UserDetailsService.html

    这里有一个创建自定义 UserDetalService 的示例: Spring Security custom UserDetailsService and custom User class

    【讨论】:

    • 感谢您的回复。能否请您给我 Spring 用于属性的类的名称,这样我就不会从头开始了。
    • 在答案中,有一个指向示例的链接,该示例准确显示了如何执行此操作。您需要实现“UserDetailsS​​ervice”接口。该链接为您提供了一个具体示例。
    猜你喜欢
    • 2013-02-22
    • 2012-01-30
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 2019-07-26
    • 1970-01-01
    相关资源
    最近更新 更多