Simple Spring MVC

David Winterfeldt

2008


There are three OSGi bundles in this example that can either be deployed individually or as part of a PAR bundle. A PAR bundle groups together your other bundles and deploys them so they aren't visible outside the PAR. In this example since a javax.sql.DataSource is exposed an OSGi service, this feature is very useful since it's quite likely at some point to want to deploy multiple services of a similar type, but each one may be specific to an application.

This example has a DataSource bundle that exposes a DataSource OSGi service for an in memory HSQL DB. There is a JPA Bundle that exposes a Person service and uses the DataSource service. The final bundle is a web application using Spring MVC to create, edit, update, delete, and search using the Person service. The example was made to be deployed on the Spring dm Server.

[Note]Note

Currently the examples are setup to only run from the Eclipse environment and to be deployed using the Spring dm Server's IDE integration. A full Maven build will eventually be added.

The simple-spring-mvc-par project has a Maven build that will download and install all the libraries and bundles needed for this example. It will install in them in '${sdms.home}/repository/libraries/usr' and '${sdms.home}/repository/bundles/usr'. Just change the property 'sdms.path' in the pom.xml to the Spring dm Server location used by Eclipse and run 'mvn package'.

1. Simple Spring MVC PAR

Manifest Configuration

There basically isn't very much to the PAR bundle since it's just a a way to group together other bundles. If you telnet into the server you'll be able to see the synthetic context the bundles were deployed under based on the PAR's bundle name. Below is a partial display of the results from running the ss.

$ telnet localhost 2401
osgi> ss
...
91	ACTIVE      org.springbyexample.sdms.simpleForm-1-org.springbyexample.sdms.simpleForm-synthetic.context_1.0.0
92	ACTIVE      org.springbyexample.sdms.simpleForm-1-org.springbyexample.sdms.simpleForm.datasource_1.0.0
93	ACTIVE      org.springbyexample.sdms.simpleForm-1-org.springbyexample.sdms.simpleForm.person_1.0.0
94	ACTIVE      org.springbyexample.sdms.simpleForm-1-org.springbyexample.sdms.simpleForm.webModule_1.0.0
...
[Note]Note

If when opening the manifest and viewing the Dependencies tab in the Eclipse IDE, it doesn't say 'PAR Editor' at the top, the default Eclipse manifest editor may have been opened. To open the Spring manifest editor, right click, 'Open with'/'Other...', and then choose the 'PAR Manifest Editor'.

src/main/resources/META-INF/MANIFEST.MF
                    
Manifest-Version: 1.0
Application-SymbolicName: org.springbyexample.sdms.simpleForm  1
Application-Version: 1.0.0
Application-Name: Simple Spring MVC PAR
Bundle-Vendor: Spring by Example
                    
                
1 The symbolic name the PAR bundle is deployed under.