Announcement Announcement Module
Collapse
No announcement yet.
Question in Spring example "Petclinic" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question in Spring example "Petclinic"

    Hi,

    First of all let's review this "petclinic-servlet.xml" file again:
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    		<property name="basename"><value>views</value></property>
    	</bean>
    
    	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    		<property name="exceptionMappings">
    			<props>
    				<prop key="org.springframework.dao.DataAccessException">dataAccessFailure</prop>
    				<prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/welcome.htm">clinicController</prop>
    				<prop key="/vets.htm">clinicController</prop>
    				<prop key="/owner.htm">clinicController</prop>
    				<prop key="/findOwners.htm">findOwnersForm</prop>
    				<prop key="/editOwner.htm">editOwnerForm</prop>
    				<prop key="/addOwner.htm">addOwnerForm</prop>
    				<prop key="/addVisit.htm">addVisitForm</prop>
    				<prop key="/addPet.htm">addPetForm</prop>
    				<prop key="/editPet.htm">editPetForm</prop>
    			</props>
    		</property>
    	</bean>
    
    
    	<bean id="clinicController" class="org.springframework.samples.petclinic.web.ClinicController">
    		<property name="methodNameResolver"><ref local="clinicControllerResolver"/></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="clinicControllerResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
    		<property name="mappings">
    		<props>
    			<prop key="/welcome.htm">welcomeHandler</prop>
    			<prop key="/vets.htm">vetsHandler</prop>
    			<prop key="/owner.htm">ownerHandler</prop>
    		</props>
    		</property>
    	</bean>
    
    	<bean id="findOwnersForm" class="org.springframework.samples.petclinic.web.FindOwnersForm">
    		<property name="formView"><value>findOwnersForm</value></property>
    		<property name="selectView"><value>selectOwnerView</value></property>
    		<property name="successView"><value>ownerRedirect</value></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="addOwnerForm" class="org.springframework.samples.petclinic.web.AddOwnerForm">
    		<property name="formView"><value>ownerForm</value></property>
    		<property name="successView"><value>ownerRedirect</value></property>
    		<property name="validator"><ref local="ownerValidator"/></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="editOwnerForm" class="org.springframework.samples.petclinic.web.EditOwnerForm">
    		<property name="formView"><value>ownerForm</value></property>
    		<property name="successView"><value>ownerRedirect</value></property>
    		<property name="validator"><ref local="ownerValidator"/></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="ownerValidator" class="org.springframework.samples.petclinic.validation.OwnerValidator"/>
    
    	<bean id="addPetForm" class="org.springframework.samples.petclinic.web.AddPetForm">
    		<property name="formView"><value>petForm</value></property>
    		<property name="successView"><value>ownerRedirect</value></property>
    		<property name="validator"><ref local="petValidator"/></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="editPetForm" class="org.springframework.samples.petclinic.web.EditPetForm">
    		<property name="formView"><value>petForm</value></property>
    		<property name="successView"><value>ownerRedirect</value></property>
    		<property name="validator"><ref local="petValidator"/></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="petValidator" class="org.springframework.samples.petclinic.validation.PetValidator"/>
    
    	<bean id="addVisitForm" class="org.springframework.samples.petclinic.web.AddVisitForm">
    		<property name="formView"><value>visitForm</value></property>
    		<property name="successView"><value>ownerRedirect</value></property>
    		<property name="validator"><ref local="visitValidator"/></property>
    		<property name="clinic"><ref bean="clinic"/></property>
    	</bean>
    
    	<bean id="visitValidator" class="org.springframework.samples.petclinic.validation.VisitValidator"/>
    
    </beans>
    The element
    Code:
    <property name="clinic"><ref bean="clinic"/></property>
    was never been defined!

    How it works?

    I'm a beginer on Spring.
    Any help would be appreciated!

    BillyW
    Thu Aug 26 10:42:29 2004 from China[/code]

  • #2
    Billy

    There are two XML attributes for bean references: "local" (checked in XML, the bean definition must be in the same XML application context); and "bean" (the bean definition can be in an ancestor context).

    The petclinic-servlet.xml file is a leaf context, that is the child of the contexts loaded by the WebApplicationContext, specified in web.xml. Thus it can see beans defined in applicationContext.xml and other contexts. The petclinic-servlet.xml file itself is concerned only with web tier functionality and "inherits" business object definitions.

    Comment


    • #3
      Got it! Thank you Rod!

      Comment

      Working...
      X