5. Adding Spring Contexts

PROBLEM

As described in the Blending Actions with non-generated Spring Beans, you can invoke logic in Spring beans using the Invoke Spring Step. By default the list of available beans will be determined by the Spring annotated beans and the Spring context configuration files generated by Skyway Builder. There will be occasions when you want to leverage logic from beans that weren't generated with Skyway Builder.

SOLUTION

There are two strategies for using your own Spring configurations with a Skyway Builder generated application. You have the option of adding to the Spring configurations generated by Skyway, in which case it will be available to the Invoke Spring Step. However you can also create your own Spring context files and add them to the project.

HOW IT WORKS

The first strategy is to add your own Spring context files to the project and reference them in the Spring Configuration tab (located in the Project Editor). With this strategy you must decide whether the beans defined in the context file should be added to the web layer or service layer. The web.xml file will be updated differently based on the configuration. Spring context files added to the web layer will be added as a contextConfigLocation init parameter for the DispatcherServler, and context files added to the service layer will be added to the contextConfigLocation context parameter.

Figure 5.2. Adding Spring Contexts to Project

Adding Spring Contexts to Project

The second strategy is to use the Spring context files that are created by Skyway Builder. Skyway Builder will generate two Spring context files for each artifact category (web, service, domain, and DAO) in an application. One context file is for maintaining the beans and related configurations that are generated by Skyway Builder, and the other context file is for non-generated beans and configurations. The generated context file (i.e. ProjectAlpha-generated-web-context.xml) should not be editted because Skyway Builder may regenerate this context file. The non-generated file (i.e. ProjectAlpha-web-context.xml) is generated when the project is orginally created, but it's never regenerated. The non-generated file also starts empty, and it's intended for the developer to configure custom non-generated Spring beans. All context files (generated and non-generated) are automatically configured in the web.xml. The developer should update the appropriate context file based on the particular category that the bean is related to. For example the service beans should be added to the xxx-service-context.xml file, and web controllers should be added to the xxx-web-context.xml file.