Hi Folks,
I am relatively new to this subject, so I need a little help.
I just started a small demo-project "bookstore" and I can't get the container working.
What I've done so far:
1. My dependencies
2. My Configuration class:Code:<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.2.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.2.0.RELEASE</version> <exclusions> <exclusion> <artifactId>commons-logging</artifactId> <groupId>commons-logging</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1-b04</version> <scope>compile</scope> </dependency> </dependencies>
3. My Initialization Class:Code:@Configuration @EnableWebMvc @ComponentScan(basePackages = {"de.logentis.bookstore.Controller"}) public class BookstoreConfiguration { @Bean public InternalResourceViewResolver configureInternalResourceViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/views/"); resolver.setSuffix(".jsp"); return resolver; } }
4. My Testcontroller:Code:public class BookstoreWebApplicationConfiguration implements WebApplicationInitializer { private WebApplicationContext createContext(final Class<?>... annotatedClasses) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(annotatedClasses); return context; } @Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext dispatcherContext = createContext(BookstoreConfiguration.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet); servletContext.addListener(new ContextLoaderListener(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); } }
As far as I can see, I didn't forget anything, did I?Code:@Controller @RequestMapping(value = "/") public class HomeController { @RequestMapping(value="/home") public String displayHome(){ return("index"); } }
Packaging the whole to a WAR and deploying in Tomcat 7.0.34 results in a simple 404, when calling "/home"
Not even a message in the log could be found, suggesting, that an appropriate route isn't configured.
Seems, that the dispatcher servlet isn't working (correctly). But I have no clue, why this is the case.
So I would be glad, if anybody points out, what I did wrong.
Thanks in advance!


Reply With Quote