java - WebApplicationInitializer not reached -
i'm building blogpost school project spring. can reach index.jsp when map other controllers 404. when set breakpoint in webapplicationinitializer in @onstartup method never gets reached. know i'm missing here? thanks!
here's code:
webapplicationinitializer:
public class initializer implements webapplicationinitializer{ @override public void onstartup(servletcontext servletcontext) throws servletexception { webapplicationcontext dispatchercontext = getcontext(); servletcontext.addlistener(new contextloaderlistener(dispatchercontext)); servletregistration.dynamic servlet = servletcontext.addservlet("dispatcher", new dispatcherservlet(dispatchercontext)); servlet.addmapping("/"); servlet.setloadonstartup(1); } private webapplicationcontext getcontext(){ annotationconfigwebapplicationcontext context = new annotationconfigwebapplicationcontext(); context.setconfiglocation("be.kdg.blogpostspringmvc.configuration"); homecoming context; } }
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>be.kdg.blogpostwebapp</groupid> <artifactid>blogpostwebapp</artifactid> <version>1.0-snapshot</version> <dependencies> <dependency> <groupid>be.kdg.spring.blogpost</groupid> <artifactid>blogpost</artifactid> <version>1.0-snapshot</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>4.1.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>4.1.1.release</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>7.0</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.1.0</version> </dependency> </dependencies>
and pom.xml of injected blogpost:
<?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>be.kdg.spring.blogpost</groupid> <artifactid>blogpost</artifactid> <version>1.0-snapshot</version> <dependencies> <dependency> <groupid>cglib</groupid> <artifactid>cglib</artifactid> <version>3.1</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>4.1.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>4.1.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> <version>4.1.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>4.1.1.release</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.11</version> </dependency> </dependencies>
change context.setconfiglocation("be.kdg.blogpostspringmvc.configuration")
context.scan("be.kdg.blogpostspringmvc.configuration")
.
setconfiglocation() used specify location of spring configuration file.
java spring maven spring-mvc
No comments:
Post a Comment