Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring DM and Services registry
    primarykey
    data
    text
    <p>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. </p> <p>The first one contains interface, and mock implementation. I want to publish them to OSGi service registry:</p> <pre><code>public interface PersonAPI { public void listAll(); public List&lt;PersonEntity&gt; getAll(); public void addPerson(PersonEntity pe); public PersonEntity getPerson(int id); } </code></pre> <p>PersonEntity is a simple class with data, nothing special. </p> <p>Mock implementation is contains just a list of PeopleEntity objects, so there is nothing interesting either. </p> <p>Here is part of Spring configuration XML:</p> <pre><code>&lt;bean id="personImpl" class="com.osgi.Person.impl.mock.PersonImpl" /&gt; &lt;osgi:service id="personLogic" ref="personImpl" interface="com.osgi.Person.PersonAPI" /&gt; </code></pre> <p>And part taken from pom.xml file:</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.felix&lt;/groupId&gt; &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.4&lt;/version&gt; &lt;extensions&gt;true&lt;/extensions&gt; &lt;configuration&gt; &lt;instructions&gt; &lt;Bundle-Category&gt;sample&lt;/Bundle-Category&gt; &lt;Bundle-SymbolicName&gt;${artifactId}&lt;/Bundle-SymbolicName&gt; &lt;Export-package&gt;com.osgi.*&lt;/Export-package&gt; &lt;/instructions&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <p>This installs fine on ServiceMix. Now I defined another bundle, here are most important parts:</p> <pre><code>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; } } </code></pre> <p>Spring configuration:</p> <pre><code>&lt;osgi:reference id="personLogic" interface="com.osgi.Person.PersonAPI" /&gt; &lt;bean id="personTester" init-method="init" class="com.osgi.Person.PersonTester"&gt; &lt;property name="api" ref="personLogic" /&gt; &lt;/bean&gt; </code></pre> <p>Most important parts from pom.xml:</p> <pre><code>&lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;com.osgi&lt;/groupId&gt; &lt;artifactId&gt;Pserson-API&lt;/artifactId&gt; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; .... &lt;plugin&gt; &lt;groupId&gt;org.apache.felix&lt;/groupId&gt; &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.4&lt;/version&gt; &lt;extensions&gt;true&lt;/extensions&gt; &lt;configuration&gt; &lt;instructions&gt; &lt;Bundle-Category&gt;sample&lt;/Bundle-Category&gt; &lt;Bundle-SymbolicName&gt;${artifactId}&lt;/Bundle-SymbolicName&gt; &lt;Import-package&gt;com.Person.entity,com.osgi.Person&lt;/Import-package&gt; &lt;/instructions&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <p>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:</p> <blockquote> <p>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</p> </blockquote> <p>It looks like It looks like AOP is missing the target, but why? And how to fix this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload