java - Spring.io and Tiles 3 - Error 404 when .war file is deployed in Tomcat server -
i error 404 when deploy generated .war file stand alone tomcat server, if deploy war inside ide(intellij) tomcat server works fine.
this initializer
public void onstartup(servletcontext servletcontext) throws servletexception { annotationconfigwebapplicationcontext mvccontext = new annotationconfigwebapplicationcontext(); mvccontext.register(appconfig.class); servletcontext.addlistener(new contextloaderlistener(mvccontext)); servletregistration.dynamic dispatcher = servletcontext.addservlet( "dispatcher", new dispatcherservlet(mvccontext)); dispatcher.setloadonstartup(1); dispatcher.addmapping("/"); }
this application configuration
**tiles configuration** @bean public tilesconfigurer gettilesconfigurer() { tilesconfigurer tilesconfigurer = new tilesconfigurer(); tilesconfigurer.setdefinitions( "/web-inf/defs/tiles.xml"); return tilesconfigurer; } @bean public urlbasedviewresolver geturlbasedresolver() { urlbasedviewresolver urlbasedviewresolver = new urlbasedviewresolver(); urlbasedviewresolver.setviewclass(new tilesview().getclass()); return urlbasedviewresolver; } /** end of tiles configuration */ **view resolver:** internalresourceviewresolver resolver = new internalresourceviewresolver(); resolver.setprefix("/web-inf/pages/**"); resolver.setsuffix(".jsp"); return resolver; **tiles.xml** <definition name="hello-tiles" extends="commons"> <put-attribute name="header" value="/web-inf/template/header2.jsp" /> <put-attribute name="title" value="hello page" /> <put-attribute name="body" value="/web-inf/pages/hello.jsp" /> </definition>
the application needs know tomcat installation path on production machine resolve paths. either can hard code in xml or can specify properties file can installation path of tomcat i.e catalina_home
or catalina_base
. reason works in ide , not on production because system understands /web-inf
in ide doesn't happen in when deploy in stand alone system.
you can append installation path of standalone server each of paths. e.g. c:/tomcat/bin
. hence need refer files like
<put-attribute name="body" value="c:/tomcat/bin/web-inf/pages/hello.jsp" />
if not fan of absolute path, can refer variables mentioned above , how use them properties file.
hope helps.
Comments
Post a Comment