当我在我的RestController中使用@Secured时出现NullPointerException

时间:2017-04-18 11:00:22

标签: java spring spring-boot spring-security

我是Spring Security的初学者,所以我用两种方法编写了一个控制器:

    public class HomeController : Controller
    {
        SessionHelper mysession = new SessionHelper();


        [HttpGet]
        [ActionName("Index")]
        public ActionResult Index_Get(string Arrival, string Departure, string Rooms, string Persons, string Childrens,  )
        {
            checkURL();
            pageload();
            ViewBag.Arrival = Arrival;
            ViewBag.Departure = Departure;
            ViewBag.Rooms = Rooms;
            ViewBag.Persons = Persons;
            ViewBag.Childrens = Childrens;
            return View(mysession);
        }
}

弹簧安全性的配置是:

value="@ViewBag.Arrival"

Moncontrôleurfonctionnebien mais lorsque j'utilise la annotation @Secured et j'authentifier j'avais l'exception:

java.lang.NullPointerException:null     在com.upsys.sec.service.EtudiantRestService.saveEtudiant(EtudiantRestService.java:29)〜[classes /:na]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_102]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_102]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_102]     在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_102]     在org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)〜[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]     在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)〜[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]     在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)〜[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]     在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapt     ....

1 个答案:

答案 0 :(得分:0)

提名saveEtudiant方法只是一个错误,它是private 我很抱歉。