java - Need help converting from web.xml spring boot -
i trying convert web.xml based web app spring boot having trouble configuring httprequesthandlerservlet. have following in web.xml:
<servlet> <servlet-name>webservices</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>updateservlet</servlet-name> <servlet-class>org.springframework.web.context.support.httprequesthandlerservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>updateservlet</servlet-name> <url-pattern>/update</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>webservices</servlet-name> <url-pattern>/ws/*</url-pattern> </servlet-mapping> the dispatcherservlet not problem:
@springbootapplication public class webapplication extends springbootservletinitializer { public static void main(string[] args) { springapplication.run(poolwebapplication.class); } @bean public dispatcherservlet dispatcherservlet() { return new dispatcherservlet(); } @bean public servletregistrationbean servletregistrationbean() { return new servletregistrationbean(dispatcherservlet(), "/ws/*"); } } but can't figure out how configure updateservlet.
how 1 configure httprequesthandlerservlet based servlet in spring boot application?
additional info:
i tried suggested answer doesn't work me.
one thing didn't mention updateservlet named "updateservlet": componenet("updateservlet") public class updateservlet implements httprequesthandler
that name conflicts bean name in answer. after changing (to update), get:
no bean named 'httprequesthandlerservlet' defined after changing name of updateservlet httprequesthandlerservlet, get
org.springframework.beans.factory.beannotofrequiredtypeexception: bean named 'httprequesthandlerservlet' must of type [org.springframework.web.httprequesthandler], of type [org.springframework.web.context.support.httprequesthandlerservlet]
for dispatcherservlet there easier way add line application.properties , remove servlet bean application class.
server.servlet-path=/ws/* next add definition of httprequesthandlerservlet configuration instead of dispatcherservlet.
@springbootapplication public class webapplication extends springbootservletinitializer { public static void main(string[] args) { springapplication.run(poolwebapplication.class); } @bean public httprequesthandlerservlet updateservlet() { return new httprequesthandlerservlet(); } @bean public servletregistrationbean updateservletregistrationbean() { return new servletregistrationbean(updateservlet(), "/update"); } } upd:
note, using updateservlet() method absolutely legal here, , can used springbean instance (see comments below).
Comments
Post a Comment