java - Spring 4 with Annotation Tomcat Deployment 404 Error -
i using spring 4, servlet 3 api , tomcat 8 project. have problem deployment. trying deploy war package in vps. using intellij idea.
i coppied war /opt/tomcat/webapps path. can see war tomcat's apps page. when try browse url 404 not found error.
i using spring annotation , empty web.xml , using spring security.
wepappinitializer.java
public class wepappinitializer implements webapplicationinitializer {  @override public void onstartup(final servletcontext servletcontext) throws servletexception {     annotationconfigwebapplicationcontext ctx = new annotationconfigwebapplicationcontext();     ctx.register(webconfig.class);     ctx.setservletcontext(servletcontext);     servletregistration.dynamic dynamic = servletcontext.addservlet("dispatcher", new dispatcherservlet(ctx));     dynamic.addmapping("/acentecilik");     dynamic.setloadonstartup(1);     } }   webconfig.java
@configuration @enablewebmvc @enabletransactionmanagement @componentscan("com.decimatech.acentecilik") @propertysource("classpath:application.properties") public class webconfig extends webmvcconfigureradapter{  @override public void addinterceptors(interceptorregistry registry) {     registry.addinterceptor(new thymeleaflayoutinterceptor()); }   @override public void addresourcehandlers(resourcehandlerregistry registry){     registry.addresourcehandler("/resources/**").addresourcelocations("/static/"); }  @bean @description("thymeleaf template resolver serving html 5") public servletcontexttemplateresolver templateresolver() {     servletcontexttemplateresolver templateresolver = new servletcontexttemplateresolver();     templateresolver.setprefix("/web-inf/html/");     templateresolver.setsuffix(".html");     templateresolver.settemplatemode("legacyhtml5");     templateresolver.setcharacterencoding("utf-8");     templateresolver.setcacheable(false);      return templateresolver; }  @bean @description("thymeleaf template engine spring integration") public springtemplateengine templateengine() {     springtemplateengine templateengine = new springtemplateengine();     templateengine.settemplateresolver(templateresolver());      return templateengine; }  @bean @description("thymeleaf view resolver") public thymeleafviewresolver viewresolver() {     thymeleafviewresolver viewresolver = new thymeleafviewresolver();     viewresolver.settemplateengine(templateengine());     viewresolver.setcontenttype("text/html;charset=utf-8");     viewresolver.setcharacterencoding("utf-8");      return viewresolver; }  @value("${spring.datasource.driver-class-name}") private string driverclassname;  @value("${spring.datasource.url}") private string datasourceurl;  @value("${spring.datasource.username}") private string datasourceusername;  @value("${spring.datasource.password}") private string datasourcepassword;  @bean(name = "datasource") public datasource getdatasource() {     drivermanagerdatasource datasource = new drivermanagerdatasource();     datasource.setdriverclassname(driverclassname);     datasource.seturl(datasourceurl);     datasource.setusername(datasourceusername);     datasource.setpassword(datasourcepassword);      return datasource; }  @autowired @bean(name = "transactionmanager") public hibernatetransactionmanager gettransactionmanager(sessionfactory sessionfactory) {     hibernatetransactionmanager transactionmanager = new hibernatetransactionmanager(sessionfactory);      return transactionmanager; }  @autowired @bean(name = "sessionfactory") public sessionfactory getsessionfactory(datasource datasource) {      localsessionfactorybuilder sessionbuilder = new localsessionfactorybuilder(datasource);      sessionbuilder.scanpackages("com.decimatech.acentecilik.model");     sessionbuilder.addproperties(gethibernateproperties());      return sessionbuilder.buildsessionfactory(); }  private properties gethibernateproperties() {     properties properties = new properties();     properties.put("hibernate.dialect", "org.hibernate.dialect.postgresqldialect");     properties.put("hibernate.hbm2ddl.auto", "update");     properties.put("hibernate.show_sql", "true");     properties.put("hibernate.format_sql", "true");     properties.put("hibernate.use_sql_comments", "true");     properties.put("hibernate.enable_lazy_load_no_trans", "true");     return properties; }  @bean public static propertysourcesplaceholderconfigurer propertysourcesplaceholderconfigurer() {     return new propertysourcesplaceholderconfigurer(); } }   web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"      xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee                   http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"      version="3.1"      metadata-complete="true">  <display-name>acentecilik</display-name> <description>     acentecilik </description> </web-app>   pom.xml
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0"      xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion>  <groupid>com.decimatech</groupid> <artifactid>acentecilik</artifactid> <version>1.0-snapshot</version>  //some package dependencies  <build>     <plugins>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-compiler-plugin</artifactid>             <version>3.3</version>             <configuration>                 <source>1.8</source>                 <target>1.8</target>             </configuration>         </plugin>          <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-resources-plugin</artifactid>             <version>2.7</version>             <configuration>                 <encoding>utf-8</encoding>             </configuration>         </plugin>     </plugins> </build>  </project>   here screenshot settings used.
project structures
tomcat manage apps page
how can solve problem?
here catalina log file's output. changed war's ownership root tomcat user. still same problem.
02-oct-2015 16:03:23.800 severe [localhost-startstop-10] org.apache.catalina.startup.contextconfig.beforestart exception fixing docbase context [/acentecilik] java.io.ioexception: unable create directory [/opt/tomcat/webapps/acentecilik] @ org.apache.catalina.startup.expandwar.expand(expandwar.java:115) @ org.apache.catalina.startup.contextconfig.fixdocbase(contextconfig.java:618) @ org.apache.catalina.startup.contextconfig.beforestart(contextconfig.java:744) @ org.apache.catalina.startup.contextconfig.lifecycleevent(contextconfig.java:307) @ org.apache.catalina.util.lifecyclesupport.firelifecycleevent(lifecyclesupport.java:95) @ org.apache.catalina.util.lifecyclebase.firelifecycleevent(lifecyclebase.java:90) @ org.apache.catalina.util.lifecyclebase.setstateinternal(lifecyclebase.java:402) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:147) @ org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:725) @ org.apache.catalina.core.containerbase.addchild(containerbase.java:701) @ org.apache.catalina.core.standardhost.addchild(standardhost.java:717) @ org.apache.catalina.startup.hostconfig.deploywar(hostconfig.java:945) @ org.apache.catalina.startup.hostconfig$deploywar.run(hostconfig.java:1798) @ java.util.concurrent.executors$runnableadapter.call(executors.java:471) @ java.util.concurrent.futuretask.run(futuretask.java:262) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745)
02-oct-2015 16:03:58.561 info [localhost-startstop-10] org.apache.jasper.servlet.tldscanner.scanjars @ least 1 jar scanned tlds yet contained no tlds. enable debug logging logger complete list of jars scanned no tlds found in them. skipping unneeded jars during scanning can improve startup time , jsp compilation time.
02-oct-2015 16:03:58.649 info [localhost-startstop-10] org.apache.catalina.startup.hostconfig.deploywar deployment of web application archive /opt/tomcat/webapps/acentecilik.war has finished in 34,860 ms
edit changed /opt/tomcat/webapps ownership tomcat , don't 404 error. have this.
info [http-nio-8080-exec-17] org.apache.catalina.core.applicationcontext.log no spring webapplicationinitializer types detected on classpath
the exception says
org.apache.catalina.startup.contextconfig.beforestart exception fixing docbase context [/acentecilik] java.io.ioexception: unable create directory
and you've stated tomcat under /opt. suppose tomcat has not sufficient permission create (write permission) on own directory /opt/tomcat.
if give write permission user launches tomcat (most own user) problem goes away.
 sudo chmod -r 0744 /opt/tomcat 




Comments
Post a Comment