Apache tomcat issue with Eclipse dynamic web module 3.0 - java

I created Spring MVC project with default configurations it was working/running on the server but when I changed Project Facets to J2EE 6 as following :
now when I run the project I get following message
UPDATE
Please see this project structure :
Controller.java is
#Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
#RequestMapping(method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
}
New Console out put without any error is :
Jun 20, 2015 6:33:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sat Jun 20 18:33:38 PKT 2015]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1a8f100: defining beans []; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 893 ms
Jun 20, 2015 6:33:39 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Sat Jun 20 18:33:39 PKT 2015]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1c047f0: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#1a8f100
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String home.com.web.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 2619 ms
with this at http://localhost:8080 also shows HTTP Status 404 Any hint in this case? What should I do?

Your problem has nothing to do with eclipse or dynamic web modules in eclipse, except there exists more than one problem. You have a general problem in your spring configuration.
You are trying to map '/' via RequestMapping - that does not work even in in Spring MVC 4.1.6 - independent of eclipse or dynamic web module.
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
- Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}"
onto public java.lang.String sd.sdse.dsdds.HomeController.home(java.util.Locale,org.springframework.ui.Model)
There are more similar questions about how define a mapping to the context root in in the spring.io forum like "#RequestMapping pointing to /"
You archive this by mapping the Spring Dispatcher Servlet to "/" not "/*"
and by removing the explicit mapping to "/" from your #RequestMapping annotations.
The Project you've shared is not the one which generates the log output. The project not even starts a SpringContext when deployed and executed on Tomcat.
To start the SpringContext you'll either have to configure the ContextLoadListener and / or DispatcherServlet in the web.xml
like here:
<display-name>Home</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Or you need a class that implements the WebApplicationInitializer interface like this one:
public class WebAppInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext context) {
XmlWebApplicationContext rootContext =
new XmlWebApplicationContext();
rootContext.setConfigLocation("/WEB-INF/spring/root-context.xml");
context.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
XmlWebApplicationContext servletContext =
new XmlWebApplicationContext();
servletContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml");
// add the dispatcher servlet and map it to /
ServletRegistration.Dynamic dispatcher =
context.addServlet("springDispatcher", new DispatcherServlet(servletContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
which loads the spring configuration files(root-context.xml, servlet-context.xml) from the locations you've used in your project.
The fixed version which uses the WebApplicationInitializer can be found on github. I've sent you a pull request.
The console output of the fixed version is:
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#76dc331c: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#5c23f9fd
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.dom.son.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'springDispatcher': initialization completed in 430 ms
Jun 21, 2015 12:45:28 PM org.apache.coyote.AbstractProtocol start
Information: Starting ProtocolHandler ["http-bio-8080"]
Jun 21, 2015 12:45:28 PM org.apache.coyote.AbstractProtocol start
Information: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 21, 2015 12:45:28 PM org.apache.catalina.startup.Catalina start
Information: Server startup in 2048 ms
INFO : com.dom.son.HomeController - Welcome home! The client locale is de_DE.
In order to fix your eclipse problem I would suggest to delete the old project from eclipse and re-import the fixed version from github.
In Eclipse:
In the Servers view stop your Tomcat instances.
Remove the deployments from your Tomcat (context menu - > delete)
Delete the Project (ideally remove it from disk, or move it to a different location)
Check out the fixed version (mine or yours with my changes)
Re-import the fixed version (File -> Import.... -> Maven -> Existing
Maven Project)

Related

Servlet cannot be resolved

I am working on a Spring MVC project which uses hibernate with postgreSQL for saving data.
I have a JSP file, which calls the action to "/user/add" residing in controller. But the error I get is the servlet cannot be resolved. I have added the jar in libraries in the project structure. I am posting the controller and JSP code here. Kindly have a look.
user.jsp
<c:url var="addAction" value="/user/add"> </c:url>
<form:form action="${addAction}" commandName="user">
<table>
<c:if test="${!empty user.first_Name}">
<tr>
<td>
<form:label path="id">
<spring:message text="UserID:"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
UserController
#RequestMapping(value="/user/add",method = RequestMethod.POST)
public String addPerson(#ModelAttribute("user") User p){
if(p.getId() == 0){
this.userService.addUser(p);
} else {
this.userService.updateUser(p);
}
return "redirect:/users";
}
Catalina.out
Sep 17, 2014 11:44:55 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /home/akshay/apache-tomcat/webapps/WirTauschen-1.0-SNAPSHOT.war
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Wed Sep 17 11:44:56 CEST 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 96 ms
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Wed Sep 17 11:44:56 CEST 2014]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/users],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.listUsers(org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/user/add],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.addPerson(com.WirTauschen.model.User)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.editPerson(int,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/remove/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.removeUser(int,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
INFO : org.hibernate.Version - HHH000412: Hibernate Core {4.3.6.Final}
INFO : org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
INFO : org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
INFO : org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
INFO : org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
INFO : org.hibernate.engine.transaction.internal.TransactionFactoryInitiator - HHH000399: Using default transaction strategy (direct JDBC transactions)
INFO : org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 914 ms
Sep 17, 2014 11:44:57 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /home/akshay/apache-tomcat/webapps/WirTauschen-1.0-SNAPSHOT.war has finished in 1,761 ms
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WirTauschen%2D1.0%2DSNAPSHOT/] in DispatcherServlet with name 'appServlet'
Hibernate: select user0_.id as id1_0_, user0_.email as email2_0_, user0_.first_Name as first_Na3_0_, user0_.last_name as last_nam4_0_, user0_.password as password5_0_ from wirtausch2 user0_
Hibernate: insert into wirtausch2 (email, first_Name, last_name, password) values (?, ?, ?, ?)
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 23502
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: null value in column "id" violates not-null constraint
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing WebApplicationContext for namespace 'appServlet-servlet': startup date [Wed Sep 17 11:44:56 CEST 2014]; parent: Root WebApplicationContext
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Wed Sep 17 11:44:56 CEST 2014]; root of context hierarchy
Kindly let me know. Thank you.
Edit : my mistake, see below
You add the context path twice.
<c:url var="addAction" value="/user/add"> </c:url> puts the full path (context path + servlet path) in addAction, and you use it in <form:form action=...>, which also adds the context path.
You should use instead :
<form:form action="/user/add" commandName="user" method="POST">
You only need to use <c:url .../> if you use the path in a link <a href="${addAction}"...>
I make confusion with the spring library for Velocity that I am used to and which directly knows about the servlet context. In true JSP, you have to use <c:url ...> to get the correct action url.
I really need the stacktrace to help you : I could do some tests and the problem is not where I thought.

Bad configuration on Spring-mvc Maven Hibernate, can't access http no mapping

i'm having some issues. I'm building an application with Spring Tool Suit, consist of SpringMVC Maven and Hibernate. I think i have all my coding ok or close to be good despite i'm noob with spring.
Here i put 2 screens of my project:
http://i.stack.imgur.com/AzhOd.png
http://i.stack.imgur.com/fBRId.png
Here i put what i think the files that are involved on the issue
aplication-config.mxl:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.springframework.samples.service"/>
</beans>
GeneralController.java:
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import form.Egg;
import service.EggService;
#Controller
//#RequestMapping("/ChickenTest/**")
public class GeneralController {
#Autowired
EggService eggService;
#RequestMapping(value="/index")
public ModelAndView index(){
ModelAndView mav = new ModelAndView();
return mav;
}
//Index of Egg webpage
#RequestMapping(value="/Egg/indexEgg")
public ModelAndView indexEgg(){
ModelAndView mav = new ModelAndView();
return mav;
}
//Action of adding an Egg
#RequestMapping(value="/Egg/addEgg", method = RequestMethod.POST)
public ModelAndView addEgg(#ModelAttribute Egg egg){
ModelAndView mav = new ModelAndView("/index");
Egg eggAux = egg;
eggService.addEgg(eggAux);
return mav;
}
//View list of eggs
#RequestMapping(value="/Egg/viewEggs", method = RequestMethod.POST)
public ModelAndView viewEggs(){
ModelAndView mav = new ModelAndView("/index");
mav.getModelMap().addAttribute("eggList", eggService.viewEggs());
return null;
}
#RequestMapping(value="/Chicken/indexChicken")
ModelAndView indexChicken(){
ModelAndView mav = new ModelAndView();
return mav;
}
#RequestMapping(value="/Farm/indexFarm")
ModelAndView indexFarm(){
ModelAndView mav = new ModelAndView();
return mav;
}
}
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ChickenTest</display-name>
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/application-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
mvc-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan
base-package="org.springframework.samples.web"/>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Here is what the console outputs when i try to enter one of my jsp:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ChickenTest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) # ChickenTest >>>
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # ChickenTest ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # ChickenTest ---
[INFO] Compiling 16 source files to C:\Java\workspace2\ChickenTest\target\classes
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:run (default-cli) # ChickenTest <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:run (default-cli) # ChickenTest ---
[INFO] Running war on http://localhost:8080/ChickenTest
[INFO] Using existing Tomcat server configuration at C:\Java\workspace2\ChickenTest\target\tomcat
Nov 08, 2013 12:31:45 AM org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
Nov 08, 2013 12:31:45 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
Nov 08, 2013 12:31:45 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Nov 08, 2013 12:31:45 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Nov 08, 2013 12:31:45 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Fri Nov 08 00:31:45 ART 2013]; root of context hierarchy
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring/application-config.xml]
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#767ae5: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Nov 08, 2013 12:31:45 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 245 ms
Nov 08, 2013 12:31:45 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcherServlet'
Nov 08, 2013 12:31:45 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcherServlet': initialization started
Nov 08, 2013 12:31:45 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcherServlet-servlet': startup date [Fri Nov 08 00:31:45 ART 2013]; parent: Root WebApplicationContext
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-config.xml]
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#132299b: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#767ae5
Nov 08, 2013 12:31:46 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcherServlet': initialization completed in 384 ms
Nov 08, 2013 12:31:46 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Nov 08, 2013 12:31:46 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Finally this is what the explorer shows when i try to enter this url http:// localhost:8080/ChickenTest/index.jsp
HTTP Status 404 - /ChickenTest/index.jsp
type Status report
message /ChickenTest/index.jsp
description The requested resource (/ChickenTest/index.jsp) is not available.
Apache Tomcat/6.0.29
Thanks for reading! i will be in touch if you need something more!
update 1:
Hi there again, i applied this solution:
First, your #Controller class is in
package controller;
so your DispatcherServlet config needs to have a component-scan on that package. So change yours to
<context:component-scan base-package="controller"/>
So that the <mvc:annotation-driven> gets applied and your #Controller class is added as a handler.
Now even if you do this, you still don't seem to have a handler method for the path
/ChickenTest/index.jsp
You'll want to either add a <welcome-file> to your web.xml and an index.jsp file in your /webapps folder or add a #RequestMapping handler method that can handler /index.jsp.
but now the console tells me that the #Autowire on GeneralController.class is not working.
This is my new error:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'generalController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.chicken.service.EggService com.chicken.controller.GeneralController.eggService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.chicken.service.EggService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
First, your #Controller class is in
package controller;
so your DispatcherServlet config needs to have a component-scan on that package. So change yours to
<context:component-scan base-package="controller"/>
So that the <mvc:annotation-driven> gets applied and your #Controller class is added as a handler.
Now even if you do this, you still don't seem to have a handler method for the path
/ChickenTest/index.jsp
You'll want to either add a <welcome-file> to your web.xml and an index.jsp file in your /webapps folder or add a #RequestMapping handler method that can handler /index.jsp.
The Exception you now get is (broken down)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'generalController':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: com.chicken.service.EggService com.chicken.controller.GeneralController.eggService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.chicken.service.EggService] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
So, the component scan couldn't create a bean for GeneralController because the Spring context could not find an EggService bean which it needs to inject into it. The only possible reason for this is that there is no EggService bean in your context. Either you haven't declared in as a <bean> or your component-scan isn't scanning the package where your EggService class is declared as a #Component.

Why is my simple springmvc web application shutting down Jetty?

Looking at my log files of a simple springmvc application (the homecontroller index action outputs 'hello world'), it seems the site is shutting down for some reason?
I simply pushed my .war file to the jetty_home/webapps folder, and started the jetty service.
ubuntu#ip-10-123-44-55:/usr/share/jetty/logs$ cat 2011_11_01.stderrout.log.022538550
2011-11-01 02:15:26.080:INFO::jetty-6.1.24
2011-11-01 02:15:26.192:INFO::Deploy /etc/jetty/contexts/javadoc.xml -> org.mortbay.jetty.handler.ContextHandler#8b819f{/javadoc,file:/usr/share/jetty/javadoc}
2011-11-01 02:15:26.338:INFO::Extract file:/var/lib/jetty/webapps/springmvc.war to /var/cache/jetty/data/Jetty__8080_springmvc.war__springmvc__s1aryk/webapp
2011-11-01 02:15:26.821:INFO::NO JSP Support for /springmvc, did not find org.apache.jasper.servlet.JspServlet
2011-11-01 02:15:28.245:INFO:/springmvc:Initializing Spring FrameworkServlet 'springmvc'
0 [main] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'springmvc': initialization started
69 [main] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Tue Nov 01 02:15:28 UTC 2011]; root of context hierarchy
145 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/servlet-context.xml]
504 [main] INFO org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
795 [main] INFO org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
853 [main] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1cd107f: defining beans [homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0]; root of factory hierarchy
1064 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Root mapping to handler 'homeController'
1446 [main] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'springmvc': initialization completed in 1445 ms
2011-11-01 02:15:29.738:INFO::NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet
2011-11-01 02:15:29.746:INFO::Opened /var/log/jetty/2011_11_01.request.log
2011-11-01 02:15:29.810:INFO::Started SelectChannelConnector#:8080
hello, world!
2011-11-01 02:24:01.775:INFO::Shutdown hook executing
2011-11-01 02:24:01.775:INFO::Graceful shutdown SelectChannelConnector#:8080
2011-11-01 02:24:01.828:INFO::Graceful shutdown org.mortbay.jetty.handler.ContextHandler#8b819f{/javadoc,file:/usr/share/jetty/javadoc}
2011-11-01 02:24:01.828:INFO::Graceful shutdown org.mortbay.jetty.webapp.WebAppContext#caf0ed{/springmvc,file:/var/lib/jetty/webapps/springmvc.war}
2011-11-01 02:24:01.828:INFO::Graceful shutdown org.mortbay.jetty.webapp.WebAppContext#18f6559{,file:/var/lib/jetty/webapps/root/}
2011-11-01 02:24:02.828:INFO::Stopped SelectChannelConnector#:8080
2011-11-01 02:24:02.829:INFO:/springmvc:Destroying Spring FrameworkServlet 'springmvc'
514583 [Shutdown] INFO org.springframework.web.context.support.XmlWebApplicationContext - Closing WebApplicationContext for namespace 'springmvc-servlet': startup date [Tue Nov 01 02:15:28 UTC 2011]; root of context hierarchy
514584 [Shutdown] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1cd107f: defining beans [homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0]; root of factory hierarchy
2011-11-01 02:24:02.834:INFO::Shutdown hook complete
This is a IntelliJ .war file that was built using a maven project.
This is my first deploy so please don't assume I know what I'm doing :)
Update
Actually it seems to be up, when I do a wget localhost:8080/springmvc/ I get the message:
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 500 JSP support not configured
2011-11-01 02:33:34 ERROR 500: JSP support not configured.
For some reason this isn't working on jetty, it worked fine on tomcat?
if this is a maven project add the yetty plugin to your pom file
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
</plugins>
then execute the following command
mvn jetty:run
According to this link
Jetty does not implement JSP directly. Instead it uses a servlet to provide this functionality required by the servle specification. [...] the companion of 2.5 servlet specification is the 2.1 JSP specification
So you need a jar with JSP.
If you're using Jetty 6 within the maven plugin I imagine that the dependency that Peter Szanto answered will solve it. On the other hand, if you are using it as part of your application you'll need to add an appropriate jsp jar.
For example for a Maven project using Jetty 6.1 you can include in the pom.xml:
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
<version>6.1.14</version>
</dependency>

DispatcherServlet doesn't appear to be processing the ModelAndView response

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<display-name>audiClave</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>rest.root</param-value>
</context-param>
<!-- Processes application requests -->
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet</servlet- class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/REST/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>base</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>base</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
base-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Scans within the base package of the application for #Components to configure as beans -->
<!-- #Controller, #Service, #Configuration, etc. -->
<context:component-scan base-package="com.audiClave.controllers" />
<!-- Enables the Spring MVC #Controller programming model -->
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Here is the BaseController:
package com.audiClave.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class BaseController {
#RequestMapping(value = "/index.html")
public ModelAndView home() {
System.out.println("BaseController: Passing through...");
return new ModelAndView("home");
// return "WEB-INF/views/home.jsp";
}
}
I call the tomcat service with:
http://localhost:8080/audiClave/index.html
and this is from the console:
BaseController: Passing through...
appears in the console window but nothing else. Content returned states:
description The requested resource () is not available.
Contents of /WEB-INF/views/home.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Audiclave</title>
</head>
<body>
<h1>Hello world from audiClave!</h1>
</body>
</html>
The problem isn't in the file though because if I return
return new ModelAndView("xxxx");
It is the same result.
It does seem to be library related as it was working before I started changing the libraries (relating to JSTL and JSP) in my project. I don't know the sequence of the libraries I have changed. I must have ended up with something incompatible with tomcat 7.
There is nothing in the tomcat log that indicates a problem. This is the startup log:
01/06/2011 9:25:20 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python26\Scripts;C:\Python26\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files\Java\jdk1.6.0_21\bin;%APPDATA%\Python\Scripts;C:\Program Files\Translate Toolkit;C:\Program Files\Gallio\bin
01/06/2011 9:25:20 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:audiClave' did not find a matching property.
01/06/2011 9:25:20 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
01/06/2011 9:25:20 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
01/06/2011 9:25:20 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 336 ms
01/06/2011 9:25:20 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
01/06/2011 9:25:20 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
01/06/2011 9:25:22 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'rest'
01/06/2011 9:25:22 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'rest': initialization started
01/06/2011 9:25:22 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'rest-servlet': startup date [Wed Jun 01 09:25:22 EST 2011]; root of context hierarchy
01/06/2011 9:25:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/rest-servlet.xml]
01/06/2011 9:25:22 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#62610b: defining beans [baseController,restController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,beanNameResolver,RemedyXml]; root of factory hierarchy
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.html] onto handler 'baseController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}] onto handler 'restController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}.*] onto handler 'restController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}/] onto handler 'restController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'rest': initialization completed in 359 ms
01/06/2011 9:25:22 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'base'
01/06/2011 9:25:22 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'base': initialization started
01/06/2011 9:25:22 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'base-servlet': startup date [Wed Jun 01 09:25:22 EST 2011]; root of context hierarchy
01/06/2011 9:25:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/base-servlet.xml]
01/06/2011 9:25:22 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#848ecc: defining beans [baseController,restController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.html] onto handler 'baseController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}] onto handler 'restController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}.*] onto handler 'restController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}/] onto handler 'restController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'base': initialization completed in 297 ms
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
01/06/2011 9:25:23 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]
01/06/2011 9:25:23 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
01/06/2011 9:25:23 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2490 ms
As per Biju's recommendation here is the log from after baseController returns the modelAndView:
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'home'
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [/WEB-INF/views/home.jsp]] in DispatcherServlet with name 'base'
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/home.jsp] in InternalResourceView 'home'
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
Register a ViewResolver in the Spring configuration along these lines:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
Now you should be able to return "home" from your controller's requestmapped method and it should correctly get resolved to "/WEB-INF/views/home.jsp" page.
You're probably missing a dependent library (which is why it fails regardless of what JSP file you specify) and your Spring context is erroring out when it tries to create something. Look carefully in catalina.out for a java.lang.NoClassDefFoundError and see if you can figure out which class it is missing.
The problem is that home.jsp does not exist in the
.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\audiClave\WEB-INF\views
directory even though in eclipse it is showing. Wasn't able to see that until I got the logging working properly.
Stopping the server, cleaning, and then republishing seems to have fixed it.

Spring MVC URI template problem

In Spring MVC 3 on Tomcat 6, I can't seem to get RequestMappings of the form /x/y/z to work. /x/y seems to work fine and that's what all the example in docs show.
For example, why does this work
#RequestMapping(value="/browse/{categoryName}");
but this is doesn't work:
#RequestMapping(value="/browse/category/{categoryName}");
Browsing to http://localhost:8080/myapp/browse/category/books generates a HTTP 404 from Tomcat. The method looks like this:
#Controller
public class BrowseController {
#RequestMapping(value = "/browse/category/{categoryName}", method = RequestMethod.GET)
public String showCategory(#PathVariable("categoryName") String categoryName, Model model) {
model.addAttribute("categoryName", categoryName);
return "Browse";
}
}
I see this message in the Tomcat output window in Netbeans 6.9:
Nov 14, 2010 2:02:03 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/myapp/browse/category/model] in DispatcherServlet with name 'dispatcher'
EDIT: added more tracing info from the log. Please disregard the timestamps since this questions was edited over two days.
Upon deploying the app:
Nov 15, 2010 9:33:28 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Nov 15 21:33:28 EST 2010]; parent: Root WebApplicationContext
Nov 15, 2010 9:33:28 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Nov 15, 2010 9:33:29 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#143c423: defining beans [browseController,homeController,showController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,viewResolver]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#1ea763a
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/browse] onto handler 'browseController'
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/browse/*] onto handler 'browseController'
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/home] onto handler 'homeController'
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/home/*] onto handler 'homeController'
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/show] onto handler 'showController'
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/show/*] onto handler 'showController'
Nov 15, 2010 9:33:29 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 501 ms
When I made the call to http://localhost:8080/myapp/browse/category/model,
Nov 15, 2010 9:34:28 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/myapp/browse/category/model] in DispatcherServlet with name 'dispatcher'
And here's my web.xml dispatcher config:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
So is there any reason why I URI pattern works but the other doesn't?
You may want to add a request mapping for the browse controller. Try this
#Controller
#RequestMapping("/browse")
public class BrowseController
{
#RequestMapping(value = "/category/{categoryName}", method = RequestMethod.GET)
public String showCategory(#PathVariable("categoryName") String categoryName, Model model)
{
model.addAttribute("categoryName", categoryName);
return "Browse";
}
}
Problem fixed on another thread:
spring-mvc: how to map URI templates in the form of "a/b/{c}"?
Your URL pattern should be /* in the servlet mapping.

Categories

Resources