首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析方法SpringSecurity

无法解析方法SpringSecurity
EN

Stack Overflow用户
提问于 2016-03-19 20:20:07
回答 1查看 987关注 0票数 0

我正在开发一个jhipster应用程序,并且我试图向我的应用程序的每个用户仅显示他创建的实体:我将此代码添加到?

PianoResourceIntTest.java:

代码语言:javascript
复制
@Test
@Transactional
public void getAllPianos() throws Exception {
    // Initialize the database

    restPianoMockMvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();
    // pianoRepository.saveAndFlush(piano);
    piano.setUser(userRepository.findOneByLogin("user").get());
    pianoRepository.saveAndFlush(piano);

    // Get all the pianos
    //restPianoMockMvc.perform(get("/api/pianos?sort=id,desc").with(user("user")))
    restPianoMockMvc.perform(get("/api/pianos?sort=id,desc").with(user("user"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.[*].id").value(hasItem(piano.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString())))
            .andExpect(jsonPath("$.[*].date").value(hasItem(DEFAULT_DATE.toString())));
}

但是我得到了两个错误:

代码语言:javascript
复制
Cannot resolve the method SpringSecurity
Cannot resolve the symbol user

我不知道如何处理这个问题,以及如何解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2016-03-20 04:55:07

我认为这些错误是编译错误,而不是运行时错误。

user()是类SecurityMockMvcRequestPostProcessors中的一个静态方法,因此需要向其添加一个静态导入。

类SecurityMockMvcConfigurers中的静态方法springSecurity()也是如此

检查Spring Security doc about Spring MVC test integration

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36101643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档