Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Does Gemini Blueprint support JSR 250 annotations?
Does Gemini Blueprint support JSR 250 annotations? [message #1807926] Wed, 12 June 2019 15:40 Go to next message
Jim Ziesig is currently offline Jim ZiesigFriend
Messages: 3
Registered: June 2019
Junior Member
Hi,

Does Gemini Blueprint support JSR 250 annotations? I am testing a long-needed migration from Spring DM 1.2.1 to Gemini Blueprint 3.0.0.M01 and found that our @PostContruct initialization methods are not being called.

Thanks,

Jim

[Updated on: Fri, 14 June 2019 13:59]

Report message to a moderator

Re: Does Gemini Blueprint support JSR 250 annotations? [message #1808287 is a reply to message #1807926] Fri, 21 June 2019 06:09 Go to previous messageGo to next message
Florian Waibel is currently offline Florian WaibelFriend
Messages: 164
Registered: June 2010
Senior Member
Hi Jim,

sorry for the late response...this example works fine for me, maybe you have something special in your code?

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class ExampleGreeter implements Greeter {

    @PostConstruct
    public void post() {
        System.out.println("Constructed!!");
    }

    @Override
    public void hello() {
        System.out.println("Hello Gemini Blueprint World!");;
    }
}


and the following `XML`

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:beans="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="de.datenkollektiv.sandbox.spring.data.jdbc.example" />

    <service ref="exampleGreeter" interface="de.datenkollektiv.sandbox.spring.data.jdbc.example.Greeter" />
</blueprint>


In the logs I can see the expected output:

[2019-06-21 08:06:32.682] INFO  region-dm-1                  System.out                                                        Constructed!!


and the OSGi service constructed:

  "Registered Services"
    {de.datenkollektiv.sandbox.spring.data.jdbc.example.Greeter}={org.eclipse.gemini.blueprint.bean.name=exampleGreeter, org.springframework.osgi.bean.name=exampleGreeter, osgi.service.blueprint.compname=exampleGreeter, ...


Hope this helps,
florian
Re: Does Gemini Blueprint support JSR 250 annotations? [message #1808352 is a reply to message #1808287] Fri, 21 June 2019 19:59 Go to previous messageGo to next message
Jim Ziesig is currently offline Jim ZiesigFriend
Messages: 3
Registered: June 2019
Junior Member
Hi Florian,

Thank you for the reply. We have a good amount of Spring-DM XML, so I was trying to maintain our original Spring-DM file format while migrating, however, I have tried using a blueprint file similar to yours for this test, and it is still not working. The classes used to verify that annotations are functional are very simple and don't include any product code. Perhaps
the platform is coming into play? I am using Karaf 4.2.5 on Java 9 and Spring 5.0.12_RELEASE_1.

The two classes used to verify functionality are:

PostConstructUser -
package test.postconstruct;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class PostConstructUser
{   
    private Integer i = null;
    
    @PostConstruct
    public void init()
    {
        System.out.println( "PostConstructUser initializing: " + this );
        i = new Integer(1);
    }

    public Integer getI()
    {
        return i;
    }

}


PostConstructTester -
package test.postconstruct;

import javax.inject.Inject;

public class PostConstructTester
{

    private PostConstructUser user;
    
    public void init()
    {
        if (user.getI() == null)
        {
            System.out.println("PostConstruct check failed.  Karaf is not properly handling annotated classes.");
        }
    }

    @Inject
    public void setUser( PostConstructUser user )
    {
        this.user = user;
    }
}


And the 'XML':
<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:beans="http://www.springframework.org/schema/beans"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
            http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
           default-activation="eager">
        
    <!--
        Enables annotation configurations (e.g. @PreDestroy,
        @PostConstruct, @Autowired)
    -->
    <context:component-scan base-package="test.postconstruct"/>
       <context:property-placeholder />

    <!--<bean id="user" class="test.test.postconstruct.PostConstructUser"/>-->
  
    <bean id="tester" class="test.postconstruct.PostConstructTester"
  	    init-method="init">
  	</bean>

</blueprint>


I install using features and these are the features 'XML' file:
<?xml version="1.0" encoding="UTF-8"?>
<features name="my-features">
<feature name="libs" version="1.0.0">
    <bundle start-level="32">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-inject/1_3</bundle>
</feature>

<feature name="gemini-blueprint" description="Eclipse Gemini Blueprint support" version="3.0.0.M01">
    <feature version="1.0.0">libs</feature>
    <feature version="5.0.12.RELEASE_1">spring</feature>
    <bundle start-level="30">mvn:org.eclipse.gemini.blueprint/gemini-blueprint-core/3.0.0.M01</bundle>
    <bundle start-level="30">mvn:org.eclipse.gemini.blueprint/gemini-blueprint-io/3.0.0.M01</bundle>
    <bundle start-level="30">mvn:org.eclipse.gemini.blueprint/gemini-blueprint-extensions/3.0.0.M01</bundle>
    <bundle start-level="30">mvn:org.eclipse.gemini.blueprint/gemini-blueprint-extender/3.0.0.M01</bundle>
    <!-- Shouldn't need this, but Gemini Blueprint doesn't include Provide-Capability header for osgi.extender=osgi.blueprint
     so the deployer feature doesn't install this bundle -->
    <!--<bundle start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.blueprint/4.2.5</bundle>-->
</feature>

<feature name="my-test-postconstruct" version="1.0.0">
    <feature version="3.0.0.M01">gemini-blueprint</feature>
    <bundle start-level="50">mvn:testing/postconstruct/3.8.0-SNAPSHOT</bundle>
</feature>

</features>


Regardless of whether I install with our product code or the simpler version, I always see the message shown below that is emitted from the tester class:

karaf@root(feature)> install libs
karaf@root(feature)> install gemini-blueprint
karaf@root(feature)> install my-test-postconstruct
karaf@root(feature)> PostConstruct check failed.  Karaf is not properly handling annotated classes.



Thanks again,

Jim

[Updated on: Fri, 21 June 2019 20:17]

Report message to a moderator

Re: Does Gemini Blueprint support JSR 250 annotations? [message #1809489 is a reply to message #1808352] Tue, 16 July 2019 19:03 Go to previous message
Jim Ziesig is currently offline Jim ZiesigFriend
Messages: 3
Registered: June 2019
Junior Member
I figured out what was wrong. My previous post had a lot of inaccuracies, but I fixed them on my local system, and after that the annotation processing worked fine with the basic features.

When I went back to our product installation, it still failed. Some of our dependencies rely on javax.annotation [1.2-2.0). jre.properties exports javax.annotation 1.0 from the system bundle, so CXF installed a javax.annotation api v1.3 bundle to satisfy its needs. That threw Spring/Gemini for a loop. I found that the javax.annotation jar in the lib/jdk9plus directory is actually version 1.3. So, I updated jre.properties to export the packages as version 1.3, and that resolved the issue.

I have opened https://issues.apache.org/jira/browse/KARAF-6358 to get the fix applied to the properties file.

Thanks again for the assistance, Florian.
Previous Topic:Blueprint Extender TaskExecutor poolSize
Next Topic:During createEntityManagerFactory "Malformed (null) URL" Hides True Exception
Goto Forum:
  


Current Time: Mon Feb 17 22:44:06 GMT 2020

Powered by FUDForum. Page generated in 0.13982 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top