This sample can mix AOP / IoC / OSGi together.
So, as shorter as possible.
The startup.bat is as:
Code:
java -Dosgi.compatibility.bootdelegation=true -cp org.eclipse.osgi_3.6.0.v20100128-1430.jar;org.eclipse.equinox.weaving.hook_1.0.0.v20100108.jar org.eclipse.core.runtime.adaptor.EclipseStarter -configuration configuration -console
the environment compounded of several bundles, for detail see configuration\config.ini:
Code:
osgi.bundles= \
org.eclipse.equinox.common_3.6.0.v20100125.jar@start, \
org.eclipse.osgi.services_3.2.100.v20100108.jar@start, \
org.eclipse.aspectj_2.0.2.e35x-20100105-0900.jar, \
org.eclipse.equinox.weaving.aspectj_1.0.0.v20100108.jar, \
org.aspectj.runtime_1.6.7.20100105084524, \
org.aspectj.weaver_1.6.7.20100105084524, \
spring-osgi-core-1.2.1.jar@start, \
spring-osgi-extender-1.2.1.jar@start, \
spring-osgi-io-1.2.1.jar@start, \
com.springsource.org.aopalliance-1.0.0.jar@start, \
org.springframework.aop-2.5.6.SEC01.jar@start, \
org.springframework.beans-2.5.6.SEC01.jar@start, \
org.springframework.context-2.5.6.SEC01.jar@start, \
org.springframework.core-2.5.6.SEC01.jar@start, \
com.springsource.slf4j.api-1.5.10.jar@start, \
com.springsource.slf4j.log4j-1.5.10.jar, \
com.springsource.slf4j.org.apache.commons.logging-1.5.0.jar@start, \
log4j.osgi-1.2.15-SNAPSHOT.jar@start, \
org.springframework.osgi.log4j.config, \
osgi.demo.api_1.0.0.jar, \
osgi.demo.impl_1.0.0.jar, \
osgi.demo.impl.log_1.0.0.jar, \
osgi.demo.oper_1.0.0.jar
# org.eclipse.equinox.weaving.caching_1.0.0.200808061839.jar@start, \
# org.eclipse.equinox.weaving.caching.j9_1.0.0.200808061839.jar@start, \
eclipse.ignoreApp=true
osgi.bundles.defaultStartLevel=5
osgi.framework=org.eclipse.osgi
osgi.configuration.cascaded=false
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
# Equinox Aspects
osgi.framework=org.eclipse.osgi_3.6.0.v20100128-1430.jar
osgi.framework.extensions=org.eclipse.equinox.weaving.hook
aj.weaving.verbose=true
org.aspectj.weaver.showWeaveInfo=true
org.aspectj.osgi.verbose=true
the last 4 bundles is for testing the environment.
**.impl.log_1.0.0.jar bundle used aop for logging the action of **.impl_1.0.0.jar
**.impl_1.0.0.jar used IoC for implementation of **.api_1.0.0.jar
and **.oper_1.0.0.jar simulated the invoker of **.impl_1.0.0.jar services
**.api_1.0.0.jar is just an interface bundle.
**.impl has spring folder under META-INF, contains 2 file:
orderservice.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="orderService" class="osgi.demo.impl.OrderServiceImpl" init-method="start" destroy-method="stop"/>
</beans>
orderservice-osgi.xml:
Code:
<?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/schem...ring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:service id="orderOSGiService" ref="orderService"
interface="osgi.demo.api.OrderApi">
</osgi:service>
</beans>
**.oper has folder spring under META-INF contains:
orderclient.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="orderClient" class="osgi.demo.oper.OrderClient"
init-method="start" destroy-method="stop">
<property name="orderService" ref="orderService"/>
</bean>
</beans>
orderclient-osgi.xml:
Code:
<?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/schem...ring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:reference id="orderService" interface="osgi.demo.api.OrderApi"/>
</beans>
MANIFEST.MF of **.log is:
Code:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Logging Aspect of lic.impl
Bundle-SymbolicName: osgi.demo.impl.log
Bundle-Version: 1.0.0
Bundle-Vendor: Regular Individual
Require-Bundle: org.aspectj.runtime;bundle-version="1.6.1";visibility:=reexport
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.apache.commons.logging;version="1.1.1",
org.osgi.framework;version="1.4.0"
Export-Package: osgi.demo.impl.log
Eclipse-SupplementBundle: osgi.demo.impl
and aop.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>
<aspect
name="osgi.demo.impl.log.OrderServiceImpl" />
</aspects>
</aspectj>
at last, the **.log4j.config has a log4j.properties in META-INF folder and with MANIFEST.MF:
Code:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Log4J Configuration
Bundle-SymbolicName: org.springframework.osgi.log4j.config
Bundle-Version: 1.0.0
Fragment-Host: org.springframework.osgi.log4j.osgi;bundle-version="1.2.15"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
OK, that's all.