【发布时间】:2014-09-03 20:51:08
【问题描述】:
当我在没有 @EnableGlobalMethodSecurity 注释的情况下运行我的应用程序时,它工作得很好。但是,我想添加对 @Secured 注释的支持,所以我想添加它。当我这样做时(如图所示),我立即开始在我的测试中获得这些异常。
@ComponentScan("ltistarter")
@Configuration
@EnableAutoConfiguration
@EnableTransactionManagement // enables TX management and @Transaction
@EnableCaching // enables caching and @Cache* tags
@EnableWebMvcSecurity // enable spring security and web mvc hooks
@EnableGlobalMethodSecurity(securedEnabled = true, proxyTargetClass = true) // allows @Secured flag
public class Application extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
...
这个异常(或类似的东西)出现在我的测试和启动时(如果我强制跳过测试):
testJPARelations(ltistarter.ApplicationTests) 经过时间:0.007 秒
它所指的类在这里:
@Transactional
public interface LtiKeyRepository extends PagingAndSortingRepository<LtiKeyEntity, Long> {
/**
* @param key the unique key
* @return the LtiKeyEntity OR null if there is no entity matching this key
*/
LtiKeyEntity findByKeyKey(String key);
/**
* @param key the unique key
* @return the number of keys removed (0 or 1)
*/
int deleteByKeyKey(String key);
}
那个类实际上不是一个类,它是一个接口,根据这里的 spring-boot JPA 指南:http://spring.io/guides/gs/accessing-data-jpa/
我怀疑这可能是这里的问题,但如果是这样,我怎样才能让 spring-jpa 和 spring-security 在 spring-boot 中一起玩得很好?
【问题讨论】:
-
试试using aspectj AOP mode .. 或者你可能在注释无效的项目(例如:尝试注释真正的类而不是接口)
-
不关注你 - 我可以通过删除 proxyTargetClass = true 来解决这个问题,但我还没有将任何东西注释为 Secured 所以我认为这不是问题
标签: spring-boot spring-security spring-data-jpa