Skip to content
Snippets Groups Projects
Commit 58d82e46 authored by Mic's avatar Mic
Browse files

handled all exception messages inside Spring config

parent aeeeace8
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.Clinic; import org.springframework.samples.petclinic.Clinic;
import org.springframework.samples.petclinic.Vets; import org.springframework.samples.petclinic.Vets;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -54,10 +55,11 @@ public class ClinicController { ...@@ -54,10 +55,11 @@ public class ClinicController {
* @return a ModelMap with the model attributes for the view * @return a ModelMap with the model attributes for the view
*/ */
@RequestMapping("/vets") @RequestMapping("/vets")
public ModelMap vetsHandler() { public String showVetList(Model model) {
Vets vets = new Vets(); Vets vets = new Vets();
vets.getVetList().addAll(this.clinic.getVets()); vets.getVetList().addAll(this.clinic.getVets());
return new ModelMap(vets); model.addAttribute("vets", vets);
return "vets";
} }
/** /**
...@@ -67,7 +69,7 @@ public class ClinicController { ...@@ -67,7 +69,7 @@ public class ClinicController {
* @return a ModelMap with the model attributes for the view * @return a ModelMap with the model attributes for the view
*/ */
@RequestMapping("/owners/{ownerId}") @RequestMapping("/owners/{ownerId}")
public ModelAndView ownerHandler(@PathVariable("ownerId") int ownerId) { public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
ModelAndView mav = new ModelAndView("owners/show"); ModelAndView mav = new ModelAndView("owners/show");
mav.addObject(this.clinic.loadOwner(ownerId)); mav.addObject(this.clinic.loadOwner(ownerId));
return mav; return mav;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
- This bean processes annotated handler methods, applying PetClinic-specific PropertyEditors - This bean processes annotated handler methods, applying PetClinic-specific PropertyEditors
- for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter. - for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter.
--> -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer"> <property name="webBindingInitializer">
<bean class="org.springframework.samples.petclinic.web.ClinicBindingInitializer"/> <bean class="org.springframework.samples.petclinic.web.ClinicBindingInitializer"/>
</property> </property>
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
<prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop> <prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
</props> </props>
</property> </property>
<property name="defaultErrorView" value="uncaughtException"/>
</bean> </bean>
<!-- <!--
...@@ -60,7 +61,8 @@ ...@@ -60,7 +61,8 @@
- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'. - property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
--> -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
<mvc:resources mapping="/resources/**" location="/resources/"/> <mvc:resources mapping="/resources/**" location="/resources/"/>
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
...@@ -69,7 +71,8 @@ ...@@ -69,7 +71,8 @@
<property name="mediaTypes"> <property name="mediaTypes">
<value> <value>
atom=application/atom+xml atom=application/atom+xml
xml=#{vets.contentType} html=text/html
xml=application/xml
</value> </value>
</property> </property>
</bean> </bean>
...@@ -77,11 +80,11 @@ ...@@ -77,11 +80,11 @@
<!-- <!--
- The BeanNameViewResolver is used to pick up the visits view name (below). - The BeanNameViewResolver is used to pick up the visits view name (below).
- It has the order property set to 2, which means that this will - It has the order property set to 1, which means that this will
- be the first view resolver to be used after the delegating content - be the first view resolver to be used after the delegating content
- negotiating view resolver. - negotiating view resolver.
--> -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<!-- <!--
- This bean configures the 'prefix' and 'suffix' properties of - This bean configures the 'prefix' and 'suffix' properties of
...@@ -90,11 +93,11 @@ ...@@ -90,11 +93,11 @@
- will be mapped to "/WEB-INF/jsp/vets.jsp". - will be mapped to "/WEB-INF/jsp/vets.jsp".
--> -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" p:order="2"/> p:suffix=".jsp" />
<!--
- The AtomView rendering a Atom feed of the visits <!-- - The AtomView rendering a Atom feed of the visits -->
-->
<bean id="visits" class="org.springframework.samples.petclinic.web.VisitsAtomView"/> <bean id="visits" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
<bean id="vets" class="org.springframework.web.servlet.view.xml.MarshallingView"> <bean id="vets" class="org.springframework.web.servlet.view.xml.MarshallingView">
......
...@@ -161,12 +161,6 @@ ...@@ -161,12 +161,6 @@
<session-timeout>10</session-timeout> <session-timeout>10</session-timeout>
</session-config> </session-config>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<!-- Displays a stack trace -->
<location>/WEB-INF/jsp/uncaughtException.jsp</location>
</error-page>
<!-- eliminate welcome files --> <!-- eliminate welcome files -->
<!-- useful for Servlet 3 container (Tomcat 7 and Jetty 6) --> <!-- useful for Servlet 3 container (Tomcat 7 and Jetty 6) -->
<welcome-file-list> <welcome-file-list>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment