Thymeleaf exception resolving template for REST Endpoint using Spring Data Rest + Spring Security -
i have setup rest endpoint
s without issue creating new endpoint
in spring
application
, have introduced spring security
. first custom endpoint
in application
security
.
rest endpoint - requestmapping
@requestmapping(value = "setuserpassword", method = requestmethod.post) public void setuserpassword(@requestbody string jsonobject) throws exception { system.out.println("in endpoint"); }
i can send http post
endpoint , have output print exception. can assume has adding spring security
have not had issues in other spring data rest
project not have spring security
.
question
what missing when configuring new rest
endpoints when spring security
enabled?
securityconfiguration
@configuration @enablewebsecurity @enableglobalmethodsecurity(prepostenabled = true) public class securityconfiguration extends websecurityconfigureradapter { @autowired private springdatajpauserdetailsservice userdetailsservice; @override protected void configure(authenticationmanagerbuilder auth) throws exception { auth .userdetailsservice(this.userdetailsservice) .passwordencoder(mcbpasswordencoder.password_encoder); } @override protected void configure(httpsecurity http) throws exception { http .authorizerequests() .antmatchers("/built/**", "/main.css").permitall() .anyrequest().authenticated() .and() .formlogin() .defaultsuccessurl("/", true) .permitall() .and() .httpbasic() .and() .csrf().and() // todo enable production .logout() .logoutsuccessurl("/"); }
exception
2016-06-01 16:34:16 - [thymeleaf][http-nio-8081-exec-1] exception processing template "setuserpassword": error resolving template "setuserpassword", template might not exist or might not accessible of configured template resolvers 2016-06-01 16:34:16 - servlet.service() servlet [dispatcherservlet] in context path [/api] threw exception [request processing failed; nested exception org.thymeleaf.exceptions.templateinputexception: error resolving template "setuserpassword", template might not exist or might not accessible of configured template resolvers] root cause org.thymeleaf.exceptions.templateinputexception: error resolving template "setuserpassword", template might not exist or might not accessible of configured template resolvers @ org.thymeleaf.templaterepository.gettemplate(templaterepository.java:246) @ org.thymeleaf.templateengine.process(templateengine.java:1104) @ org.thymeleaf.templateengine.process(templateengine.java:1060) @ org.thymeleaf.templateengine.process(templateengine.java:1011) @ org.thymeleaf.spring4.view.thymeleafview.renderfragment(thymeleafview.java:335) @ org.thymeleaf.spring4.view.thymeleafview.render(thymeleafview.java:190) @ org.springframework.web.servlet.dispatcherservlet.render(dispatcherservlet.java:1243) @ org.springframework.web.servlet.dispatcherservlet.processdispatchresult(dispatcherservlet.java:1027) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:971) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:968) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:870) @ javax.servlet.http.httpservlet.service(httpservlet.java:648) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:844) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:292) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:316) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:126) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:90) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:114) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:122) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:111) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:169) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:48) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.authentication.www.basicauthenticationfilter.dofilterinternal(basicauthenticationfilter.java:213) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.authentication.ui.defaultloginpagegeneratingfilter.dofilter(defaultloginpagegeneratingfilter.java:162) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:205) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:120) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.header.headerwriterfilter.dofilterinternal(headerwriterfilter.java:64) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:91) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:53) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:213) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:176) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:346) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:262) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.springframework.web.filter.requestcontextfilter.dofilterinternal(requestcontextfilter.java:99) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.springframework.web.filter.httpputformcontentfilter.dofilterinternal(httpputformcontentfilter.java:87) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.springframework.web.filter.hiddenhttpmethodfilter.dofilterinternal(hiddenhttpmethodfilter.java:77) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:121) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:212) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:141) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:522) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1095) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:672) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1500) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1456) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745)
solution
adding correct @requestbody @controller
@requestbody map<string, object> payload
i think problem not related spring security configuration controller method instead.
in exception getting when calling method says trying find thymeleaf response view related method. method doesn't return view name, spring mvc trying find thymeleaf view same name method name.
add @responsebody annotation method , produces = mediatype.application_json_value requestmapping annotation narrow supported media types.
also you'll have handle response, returning , object or yourself. take @ supported method return types