I'm learning Spring DM and I have a problem with Service registry. I'm using ServiceMix 4.3.0 with embedded Felix instance. I have 2 bundles in my project.
The first one contains interface, and mock implementation. I want to publish them to OSGi service registry:
public interface PersonAPI {
public void listAll();
public List<PersonEntity> getAll();
public void addPerson(PersonEntity pe);
public PersonEntity getPerson(int id);
}
PersonEntity is a simple class with data, nothing special.
Mock implementation is contains just a list of PeopleEntity objects, so there is nothing interesting either.
Here is part of Spring configuration XML:
<bean id="personImpl" class="com.osgi.Person.impl.mock.PersonImpl" />
<osgi:service id="personLogic" ref="personImpl" interface="com.osgi.Person.PersonAPI" />
And part taken from pom.xml file:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Category>sample</Bundle-Category>
<Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
<Export-package>com.osgi.*</Export-package>
</instructions>
</configuration>
</plugin>
This installs fine on ServiceMix. Now I defined another bundle, here are most important parts:
public class PersonTester {
PersonAPI api;
public void init() {
System.out.println("PostConstruct:");
System.out.println("Have API " + api + " class " + api.getClass().getCanonicalName());
api.listAll(); //This line (or any API call, blows everything)
}
public PersonAPI getApi() {
return api;
}
public void setApi(PersonAPI api) {
this.api = api;
}
}
Spring configuration:
<osgi:reference id="personLogic" interface="com.osgi.Person.PersonAPI" />
<bean id="personTester" init-method="init" class="com.osgi.Person.PersonTester">
<property name="api" ref="personLogic" />
</bean>
Most important parts from pom.xml:
<dependencies>
<dependency>
<groupId>com.osgi</groupId>
<artifactId>Pserson-API</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
....
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Category>sample</Bundle-Category>
<Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
<Import-package>com.Person.entity,com.osgi.Person</Import-package>
</instructions>
</configuration>
</plugin>
The good news is, that "behind" injected Spring proxy is my implementation class. I can see that when using api.toString(). However when I call any method defined in my proxy, I get an exception:
Exception in thread "SpringOsgiExtenderThread-88" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personTester': Invocation of init method failed; nested exception is org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract void com.osgi.Person.PersonAPI.listAll()] on target [PersonImpl [set=[]]]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
It looks like It looks like AOP is missing the target, but why? And how to fix this?