【问题标题】:java.lang.IllegalAccessException:.cannot access the member of class CrossOrigin with modifiers "private static"java.lang.IllegalAccessException:.cannot 使用修饰符“private static”访问类 CrossOrigin 的成员
【发布时间】:2020-01-06 09:51:15
【问题描述】:

我正在尝试使用带有@CrossOrigin 注释的一些端点来模拟控制器类。它给出了这个例外。

原因:java.lang.IllegalAccessException:类 net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation 无法使用修饰符“private static”访问类 org.springframework.web.bind.annotation.CrossOrigin 的成员

@Runwith(PowerMockRunner.class)
class TestDemo
{
@Mock
private ControllerTest con;
}

class ControllerTest
{
@CrossOrigin
@RequestMapping
public void testCon()
{
//code implementation
}
}

【问题讨论】:

  • 添加您的控制器类和相关类代码,以便我们了解问题
  • 删除不必要的堆栈轨道

标签: java spring-boot mockito powermockito spring-boot-test


【解决方案1】:
  • 这将对您有所帮助
  • 可以使用注解@CrossOrigin
@CrossOrigin(origins = {"http://localhost:85960"}, maxAge = 5000, allowCredentials = "false")
@CrossOrigin(origins = {"http://localhost:5960"}, maxAge = 5000, allowCredentials = "false")
@RestController
@RequestMapping("/api")
public class testRestController{

    @CrossOrigin(origins = {"http://localhost:5959"}, maxAge = 800)
    @RequestMapping("/test")
    public List<Student> showData() {
        List<Student> studentlist = List<Student>();
        return studentlist 
    }

} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 1970-01-01
    • 2012-06-23
    • 2021-01-15
    • 2015-07-24
    • 2020-02-05
    相关资源
    最近更新 更多