springboot shiro沒有註解解決方案 springboot shiro開啟註釋
阿新 • • 發佈:2018-12-23
頹廢的悠然
springboot shiro開啟註釋
shiroconfiguration中增加
1 2 3 4 5 6 7 |
@Bean
public
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor
=
new
AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
return
authorizationAttributeSourceAdvisor;
}
|
在controller中的方法前加上註解
1 |
@RequiresPermissions
(
"userInfo:test"
)
|
若還沒生效,應該是aop沒起作用,
解決方法一
shiroconfiguration中增加
1 2 3 4 5 6 7 |
@Bean
@ConditionalOnMissingBean
public
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAAP =
new
DefaultAdvisorAutoProxyCreator();
defaultAAP.setProxyTargetClass(
true
);
return
defaultAAP;
}
|
解決方法二
pom.xml中加入
1 2 3 4 |
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
|
同時application.properties中補充
1 |
spring.aop.proxy-target-
class
=
true
|
shiroconfiguration中增加
1 2 3 4 5 6 7 |
@Bean
public
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor
=
new
AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
return
authorizationAttributeSourceAdvisor;
}
|
在controller中的方法前加上註解
1 |
@RequiresPermissions
(
"userInfo:test"
)
|
若還沒生效,應該是aop沒起作用,
解決方法一
shiroconfiguration中增加
1 2 3 4 5 6 7 |
@Bean
@ConditionalOnMissingBean
public
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAAP =
new
DefaultAdvisorAutoProxyCreator();
defaultAAP.setProxyTargetClass(
true
);
return
defaultAAP;
}
|
解決方法二
pom.xml中加入
1 2 3 4 |
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
|
同時application.properties中補充
1 |
spring.aop.proxy-target-
class
=
true
|