Examining the Petclinic Startup Sequence

In the remainder of this appendix, we cover the noteworthy code and configuration files you need to run the Petclinic application.

Because the Petclinic sample is a regular Java application, it must have a main() method that configures the application environment. Listing B-4 shows that the main() method is implemented in the PetClinicStandalone class.

Listing B-4: PetClinicStandalone Main Class

image from book
package org.springframework.richclient.samples.petclinic;      import org.springframework.richclient.application.ApplicationLauncher;      public class PetClinicStandalone {          public static void main(String[] args) {         try {             String rootContextDirectoryClassPath =                "/org/springframework/richclient/samples/petclinic/ctx";             String startupContextPath = rootContextDirectoryClassPath +                  "/common/richclient-startup-context.xml";             String richclientApplicationContextPath =                   rootContextDirectoryClassPath +                  "/common/richclient-application-context.xml";             String richclientPreferenceContextPath =                  rootContextDirectoryClassPath +                  "/common/richclient-preference-context.xml";             String businessLayerContextPath = rootContextDirectoryClassPath +                  "/common/business-layer-context.xml";             String securityContextPath = rootContextDirectoryClassPath +                  "/standalone/security-context.xml";                  new ApplicationLauncher(startupContextPath,                  new String[] { richclientApplicationContextPath,                     richclientPreferenceContextPath, businessLayerContextPath,                      securityContextPath });         } catch (Exception e) {             System.exit(1);         }     } }
image from book

The main() method simply sets up variables representing paths to the Spring application context files and creates an instance of the ApplicationLauncher. The first parameter is the path to the startup context file, which is loaded before the root application context is constructed. Typically, you need to include the beans that are essential to the application startup stage and keep the remaining beans in the files in the root context.

The code in Listing B-5 shows the ctx/common/richclient-startup-context.xml file, which defines the splashScreen bean. The ApplicationLauncher looks up the bean with this ID and if it exists, it is displayed while the full application context is being built.

Listing B-5: richclient-startup-context.xml File

image from book
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"      "http://www.springframework.org/dtd/spring-beans.dtd"> <beans>     <bean bold">splashScreen"          bold">SplashScreen"          singleton="false">         <property name="imageResourcePath">             <value>/images/splash-screen.jpg</value>         </property>     </bean> </beans>
image from book

The usage and purpose of the startup context file is to quickly build a minimal platform and to display basic user interface elements to let the user know that the application is starting up.

Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net