Since OSGi, with its class wiring, versioning, reloading, superseeds the WAR classpath, Spring DM will ignore the WAR predefined locations and will always use the OSGi classpath instead. This means that classes imported by a WAR bundle can be used even if they are not present under WEB-INF/classes folder or inside a jar under WEB-INF/lib. This also means that any class under WEB-INF/classes will not be considered if it’s not available in the WAR OSGi classpath.

the easiest ways to support the pre-defined WAR locations, is to add them to the bundle classpath, by adding them to the bundle manifest:

Bundle-Classpath: .,WEB-INF/classes,WEB-INF/lib/some.jar,WEB-INF/lib/lib.jar

tag lib

the tag definitions are automatically discovered, the tag classes are not - again, the OSGi classpath takes priority. When dealing with libraries that export a lot of tags, one can use the Require-Bundle header instead of Import-Package for importing the tags:

Require-Bundle: org.springframework.osgi.jstl.osgi

Configuration

The Service Registry

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
 
    <bean id="weatherDao" class="org.springframework.osgi.samples.weather.dao.StaticDataWeatherDaoImpl"/>
 
    <osgi:service ref="weatherDao" interface="org.springframework.osgi.samples.weather.dao.WeatherDao"/>
 
</beans>

Using Service

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
 
    <bean id="weatherService"
        class="org.springframework.osgi.samples.weather.service.WeatherServiceImpl">
        <property name="weatherDao">
            <osgi:reference interface="org.springframework.osgi.samples.weather.dao.WeatherDao"/>
        </property>
    </bean>
 
 
    <osgi:service ref="weatherService">
        <osgi:interfaces>
            <value>org.springframework.osgi.samples.weather.service.WeatherService</value>
        </osgi:interfaces>
        <osgi:service-properties>
            <entry key="foo" value="bar"/>
            <entry key="baz" value="myprop"/>
        </osgi:service-properties>
    </osgi:service>
 
</beans>