-1

I am trying to mock the controller class with some endpoints annotated with @CrossOrigin. it is giving this exception.

Caused by: java.lang.IllegalAccessException: Class net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation can not access a member of class org.springframework.web.bind.annotation.CrossOrigin with modifiers "private static"

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

class ControllerTest
{
@CrossOrigin
@RequestMapping
public void testCon()
{
//code implementation
}
}
Sourav Sharma
  • 371
  • 1
  • 4
  • 9

1 Answers1

0
  • this will help to you
  • You can use annotation @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 
    }

} 
Dulaj Kulathunga
  • 1,248
  • 2
  • 9
  • 19