Red5Pro: Autowiring custom dependencies in custom webapp

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Red5Pro: Autowiring custom dependencies in custom webapp

Herb Jellinek
Hi all,
I've written a custom webapp that looks like so:

package my.package.webapp;

import my.package.io.MyUploader;

public class Notifier extends MultiThreadedApplicationAdapter {

    private final Logger log = Red5LoggerFactory.getLogger(getClass());

    private MyUploader uploader;

    @Override
public boolean appStart(final IScope app) {
        log.info("uploader = {}", uploader);
    }

    ...

}

I've got a JAR file, MyJar.jar, created as part of a separate project, that includes the class my.package.io.MyUploader.  The JAR contains a Spring app, and MyUploader is a singleton, annotated as a @Service.

I've added MyJar.jar to the webapp's pom.xml as a provided dependency, and the webapp compiles as I'd expect.

I copied MyJar.jar to my Red5Pro server's lib directory.

=> I want Notifier to have its uploader field set to an instance of my.package.io.MyUploader at startup using Spring dependency injection

I edited the webapp's red5-web.xml file and added various <bean .../> declarations like so:

<bean id="uploader" class="my.package.io.Uploader" autowire="byType"/>

I also tried omitting the autowire declaration, tried using byName, and more.

What I expect:

The appStart method runs.
The log shows

uploader = my.package.io.MyUploader@xxxxxx

What actually happens:

The appStart method runs.
The log shows

uploader = null

My Question:

How do I arrange it so my Notifier class gets a MyUploader instance injected into its uploader field?

I normally use Spring with annotation-based dependency management, so I may have overlooked something obvious in my XML.

Thanks,

    Herb

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Red5Pro: Autowiring custom dependencies in custom webapp

Rajdeep Rath
Don't use autowire. Create a property in your Notifier class of type Uploader. Create getter setter for it .


In red5-web.xml instantiate your component as you have shown. Then pass the reference to your Notifier (web.handler) like so:

 <property name="uploader" ref="uploader" />


Where bean I'd is uploader and also your property in Notifier class is called uploader.

On Fri, 26 Oct, 2018, 2:07 AM Herb Jellinek, <[hidden email]> wrote:
Hi all,
I've written a custom webapp that looks like so:

package my.package.webapp;

import my.package.io.MyUploader;

public class Notifier extends MultiThreadedApplicationAdapter {

    private final Logger log = Red5LoggerFactory.getLogger(getClass());

    private MyUploader uploader;

    @Override
public boolean appStart(final IScope app) {
        log.info("uploader = {}", uploader);
    }

    ...

}

I've got a JAR file, MyJar.jar, created as part of a separate project, that includes the class my.package.io.MyUploader.  The JAR contains a Spring app, and MyUploader is a singleton, annotated as a @Service.

I've added MyJar.jar to the webapp's pom.xml as a provided dependency, and the webapp compiles as I'd expect.

I copied MyJar.jar to my Red5Pro server's lib directory.

=> I want Notifier to have its uploader field set to an instance of my.package.io.MyUploader at startup using Spring dependency injection

I edited the webapp's red5-web.xml file and added various <bean .../> declarations like so:

<bean id="uploader" class="my.package.io.Uploader" autowire="byType"/>

I also tried omitting the autowire declaration, tried using byName, and more.

What I expect:

The appStart method runs.
The log shows

uploader = my.package.io.MyUploader@xxxxxx

What actually happens:

The appStart method runs.
The log shows

uploader = null

My Question:

How do I arrange it so my Notifier class gets a MyUploader instance injected into its uploader field?

I normally use Spring with annotation-based dependency management, so I may have overlooked something obvious in my XML.

Thanks,

    Herb

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Red5Pro: Autowiring custom dependencies in custom webapp

Herb Jellinek
Excellent - thanks for the quick reply.  For the benefit of others coming across this later, here's what I did:

- Added public getUploader and setUploader methods to my.package.Notifier.

- Modified red5-web.xml like so:

<bean id="uploader" class="my.package.io.MyUploader"/>

<bean id="web.handler" class="my.package.Notifier">
<property name="uploader" ref="uploader" />
</bean>

And now the uploader field contains a MyUploader instance by the time appStart runs.

        Herb

On Thursday, October 25, 2018 at 1:48:27 PM UTC-7, Rajdeep Rath wrote:
Don't use autowire. Create a property in your Notifier class of type Uploader. Create getter setter for it .


In red5-web.xml instantiate your component as you have shown. Then pass the reference to your Notifier (web.handler) like so:

 <property name="uploader" ref="uploader" />


Where bean I'd is uploader and also your property in Notifier class is called uploader.

On Fri, 26 Oct, 2018, 2:07 AM Herb Jellinek, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="X4jhDPJJBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">herb.j...@...> wrote:
Hi all,
I've written a custom webapp that looks like so:

package my.package.webapp;

import my.package.io.MyUploader;

public class Notifier extends MultiThreadedApplicationAdapter {

    private final Logger log = Red5LoggerFactory.getLogger(getClass());

    private MyUploader uploader;

    @Override
public boolean appStart(final IScope app) {
        <a href="http://log.info" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flog.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGiFwT-1qFB2PcvymGq972yAwReIA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flog.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGiFwT-1qFB2PcvymGq972yAwReIA&#39;;return true;">log.info("uploader = {}", uploader);
    }

    ...

}

I've got a JAR file, MyJar.jar, created as part of a separate project, that includes the class my.package.io.MyUploader.  The JAR contains a Spring app, and MyUploader is a singleton, annotated as a @Service.

I've added MyJar.jar to the webapp's pom.xml as a provided dependency, and the webapp compiles as I'd expect.

I copied MyJar.jar to my Red5Pro server's lib directory.

=> I want Notifier to have its uploader field set to an instance of my.package.io.MyUploader at startup using Spring dependency injection

I edited the webapp's red5-web.xml file and added various <bean .../> declarations like so:

<bean id="uploader" class="my.package.io.Uploader" autowire="byType"/>

I also tried omitting the autowire declaration, tried using byName, and more.

What I expect:

The appStart method runs.
The log shows

uploader = my.package.io.MyUploader@xxxxxx

What actually happens:

The appStart method runs.
The log shows

uploader = null

My Question:

How do I arrange it so my Notifier class gets a MyUploader instance injected into its uploader field?

I normally use Spring with annotation-based dependency management, so I may have overlooked something obvious in my XML.

Thanks,

    Herb

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="X4jhDPJJBwAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">red5interest...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.