Springboot中@Configuration和@bean注解怎么用
作者:BrightSoul
时间:2023-05-15
来源:正软商城
浏览:0
@Configuration注解可以达到在Spring中使用xml配置文件的作用@Bean就等同于xml配置文件中的在spring项目中我们集成第三方的框架如shiro会在spring.xml配置文件中进行配置,例如:/css/**=anon/js/**=anon/validatecode.jsp*=anon/images/**=anon/login.jsp=anon/service/**=anon/**=authc在springboot与shiro整合:@Configurationpublicclass
本文目录
@Configuration注解可以达到在Spring中使用xml配置文件的作用
@Bean就等同于xml配置文件中的
在spring项目中我们集成第三方的框架如shiro会在spring.xml配置文件中进行配置,例如:
/css/**=anon /js/**=anon /validatecode.jsp*=anon /images/**=anon /login.jsp=anon /service/**=anon /**=authc
在springboot与shiro整合:
@Configuration
public class ShiroConfig {
@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
Map filterChainDefinitionMap = new HashMap();
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setUnauthorizedUrl("/unauthc");
shiroFilterFactoryBean.setSuccessUrl("/home/index");
filterChainDefinitionMap.put("/*", "anon");
filterChainDefinitionMap.put("/authc/index", "authc");
return shiroFilterFactoryBean;
}
@Bean
public HashedCredentialsMatcher hashedCredentialsMatcher() {
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
hashedCredentialsMatcher.setHashAlgorithmName(PasswordHelper.ALGORITHM_NAME);
hashedCredentialsMatcher.setHashIterations(PasswordHelper.HASH_ITERATIONS);
return hashedCredentialsMatcher;
}
@Bean
public EnceladusShiroRealm shiroRealm() {
EnceladusShiroRealm shiroRealm = new EnceladusShiroRealm();
shiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
return shiroRealm;
}
@Bean
public SecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(shiroRealm());
return securityManager;
}
@Bean
public PasswordHelper passwordHelper() {
return new PasswordHelper();
}
} @Configuration注解可以达到在Spring中使用xml配置文件的作用。
@Bean就等同于xml配置文件中的
作者最新文章
一加手机安装立刻MV外部应用设置教程
2026-11-05 16:52
漫蛙漫画免费下拉式在线看地址
2026-10-27 17:25
如何在WPSOffice2019一键开启和关闭筛选
2026-10-26 23:11
xmind怎么调整两个框之间的距离 布局技巧
2026-10-24 13:34
ps怎么抠图
2026-10-20 17:22
下一篇:
2023年影响设建筑施管理发展的技术趋势
热门文章
更多
精品专题
更多
Mac软件
更多
火山引擎 网页版
Windows/ macOS/ Linux
火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。








