This is the same as the 1.0 version of the Message Service bundle, but it has it's version set to 1.1.0 on the Bundle-Version property and also depends on Commons Lang 2.4.0.
Manifest-Version: 1.0 Bundle-Name: Simple Service Bundle Bundle-Description: Simple Service Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.springbyexample.sdms.message.messageService Bundle-Version: 1.1.0 Import-Library: org.aspectj, org.springframework.spring Import-Bundle: com.springsource.org.apache.commons.lang;version="[2.4.0,2.4.0]" Export-Package: org.springbyexample.sdms.message.service;version="1.1.0"
The version 1.1 of MessageServiceImpl
has a different message than version 1.0.
Also the implementation uses a Commons Lang 2.4.0 specific method call that is appended to the message.
<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="messageService" class="org.springbyexample.sdms.message.service.impl.MessageServiceImpl" p:message="Greetings from Spring by Example!"/> </beans>
The messageService bean is exposed as a service under the
interface org.springbyexample.sdms.message.service.MessageService
.
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" 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"> <service ref="messageService" interface="org.springbyexample.sdms.message.service.MessageService"/> </beans:beans>
The MessageService
interface is identical to the one in the Message Service Bundle 1.0 class.
So the Message Service Web Module can dynamically use either implementation's service.
Example 3. Message Service MessageService
(version 1.1)
public interface MessageService { /** * Gets message. */ public String getMessage(); }
This implementation uses FastDateFormat
from Commons Lang 2.4.0 to display a formatted date
after the message that will be injected from the Spring configuration. It also uses StringUtils.length(String)
to add the message length at the end of the message. This method was adding Commons Lang 2.4.0. If you try to use this
method in the Message Service Bundle 1.0 implementation, you will see that it won't be able to find that method on StringUtils
.
Example 4. Message Service MessageServiceImpl
(version 1.1)
public class MessageServiceImpl implements MessageService { private String message = null; /** * Gets message. */ public String getMessage() { StringBuffer sb = new StringBuffer(); sb.append(message); sb.append(" ["); sb.append(FastDateFormat.getInstance("MM/dd/yyyy").format(new Date())); sb.append("]"); // add Commons Lang StringUtils.length(String) which was specifically added in Commons Lang 2.4.0) sb.append(" (message length="); sb.append(StringUtils.length(message)); sb.append(")"); return sb.toString(); } /** * Sets message. */ public void setMessage(String message) { this.message = message; } }