Purely java base spring web mvc application showing 404
arpan88 Nov 27, 2013 12:58 PMHi all,
I am new to spring web mvc. I have created an application of which all the configurations are purely java based (not even the web.xml is there). The problem is it is perfectly working on tomcat 7 but showing 404 on jboss as 7. I got no deployment error on both the server. Could not figure it out. Any one can help ? It's a maven project. Below is my code
IConfigConstants.java
/** * */ package org.ec.app.config.constants; /** * @author arpan * */ public interface IConfigConstants { public static final String CONFIG_LOCATION = "org.ec.app.config"; public static final String MAPPING_URL = "/"; public static final Integer LOAD_ON_STARTUP_VALUE=1; public static final String RESOURCE_HANDLER="/resources/**"; public static final String RESOURCE_LOCATION="/resources/"; public static final String CSS_HANDLER="/css/**"; public static final String CSS_LOCATION="/css/"; public static final String IMAGE_HANDLER="/img/**"; public static final String IMAGE_LOCATION="/img/"; public static final String SCRIPT_HANDLER="/scripts/**"; public static final String SCRIPT_LOCATION="/script/"; public static final Integer CACHE_PERIOD_DEFAULT=30*24*3600*1000; public static final Integer CACHE_PERIOD_6_MONTHS=6*30*24*3600*1000; public static final Integer CACHE_PERIOD_YEAR=365*24*3600*1000; }
AppInitializer.java
/** * */ package org.ec.app.main; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import org.apache.log4j.Logger; import org.ec.app.config.AppConfig; import org.ec.app.config.constants.IConfigConstants; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; /** * @author arpan * */ public class AppInitializer implements WebApplicationInitializer{ private static final Logger log = Logger.getLogger(AppInitializer.class); @Override public void onStartup(ServletContext servletContext) throws ServletException { log.info("onStartup() method invoked"); WebApplicationContext webContext = getContext(); servletContext.addListener(new ContextLoaderListener(webContext)); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(webContext)); dispatcher.setLoadOnStartup(IConfigConstants.LOAD_ON_STARTUP_VALUE); dispatcher.addMapping(IConfigConstants.MAPPING_URL); } private AnnotationConfigWebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(AppConfig.class); return context; } }
Appconfig.java
/** * */ package org.ec.app.config; import org.apache.log4j.Logger; import org.ec.app.config.constants.IConfigConstants; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; /** * @author arpan * */ @EnableWebMvc @ComponentScan(basePackages={"org.ec.app"}) @Configuration public class AppConfig extends WebMvcConfigurerAdapter { private static final Logger log = Logger.getLogger(AppConfig.class); @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { log.info("addResourceHandlers() method invoked"); registry.addResourceHandler(IConfigConstants.RESOURCE_HANDLER).addResourceLocations(IConfigConstants.RESOURCE_LOCATION).setCachePeriod(IConfigConstants.CACHE_PERIOD_DEFAULT); registry.addResourceHandler(IConfigConstants.IMAGE_HANDLER).addResourceLocations(IConfigConstants.IMAGE_LOCATION).setCachePeriod(IConfigConstants.CACHE_PERIOD_DEFAULT); registry.addResourceHandler(IConfigConstants.CSS_HANDLER).addResourceLocations(IConfigConstants.CSS_LOCATION).setCachePeriod(IConfigConstants.CACHE_PERIOD_DEFAULT); registry.addResourceHandler(IConfigConstants.SCRIPT_HANDLER).addResourceLocations(IConfigConstants.SCRIPT_LOCATION).setCachePeriod(IConfigConstants.CACHE_PERIOD_DEFAULT); } @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer) { log.info("configureDefaultServletHandling() method invoked"); configurer.enable(); } @Bean public InternalResourceViewResolver getInternalResourceViewResolver() { log.info("getInternalResourceViewResolver() method invoked"); InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/pages/"); resolver.setSuffix(".jsp"); return resolver; } }
and TestController.java
/** * */ package org.ec.app.controller; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * @author arpan * */ @Controller public class TestController { private static final Logger log = Logger.getLogger(TestController.class); @RequestMapping(value="/",method=RequestMethod.GET) public String getHomePage() { log.info("getHomePage() method invoked"); return "index"; } }
finally the pom.xml
<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>EnterpriseCollaboration</groupId> <artifactId>EnterpriseCollaboration</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>EnterpriseCollaboration</name> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>3.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>3.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>1.3.2.RELEASE</version> </dependency> <!-- <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-xml</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-security</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-oxm</artifactId> <version>1.5.10</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-oxm-tiger</artifactId> <version>1.5.10</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core-tiger</artifactId> <version>1.5.10</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-support</artifactId> <version>2.1.4.RELEASE</version> </dependency> --> <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-core</artifactId> <version>2.2.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.mobile</groupId> <artifactId>spring-mobile-device</artifactId> <version>1.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-webflow</artifactId> <version>2.3.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-support</artifactId> <version>2.0.8</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>3.0</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> </project>
I have also attached the source here.
-
AppConfig.java 2.3 KB
-
IConfigConstants.java 970 bytes
-
AppInitializer.java 1.5 KB
-
TestController.java 558 bytes
-
index.jsp.zip 368 bytes
-
pom.xml 3.5 KB