Stubbisms – Tony’s Weblog

July 8, 2009

Spring Modules Fork

Filed under: Java — Tags: , , , — Antony Stubbs @ 10:45 pm
Ok guys – the project is up on git-hub!
Install Git! – http://git-scm.com/
To download an anonymous repository run http://github.com/astubbs/spring-modules or sign up with git-hub and get your personal account!
Let the patching begin!
From the Wiki page: “””
This is a resurection of the extremely valuable and abandoned Spring-Modules project.
The plan is to fully embrace Maven as the build tool and eventually throw out all the old build code.
At this point, all the old jar libraries and generated documentation have been pruned from the repository history.
This pruning has reduced the size of the repository from 95m to 7m. Nice.
The idea will be to slowly add one by one, as the are compile ready, to the parent module section, so they can be included.
Msg/email me on antony.stubbs@gmail.com to discuss!
“””
I will try and get a development mailing list setup asap, but for now, email me on antony.stubbs@gmail.com with the [subject spring-module-fork] and I’ll start building a manual list.

One thing I want to discuss is ow we can organise the issues on jira :/ I still have had no response from InspiSpring.

The project website: http://wiki.github.com/astubbs/spring-modules

Inspired by my work with Spring Modules (or difficulties with), and as explained in this post on the Spring Modules forum, I am now announcing the Spring Modules Fork! An effort to bring back to life some very useful software!

I have emailed various people and even emailed suggesting an extensions project as described on the Spring site[1] but haven’t had any responses.

As Spring Modules has been officially declared dead [2] and i’m not getting nay replies to my mails I would like to fork the project into git-hub and get some vital patches applied – particularly on my area of interest – the cache module. I also would like to migrate the whole project to maven.

I’m posting here to get any thoughts or suggestions regarding this – hopefully a response from someone at Spring – particularly Colin Yates.

Let’s get this useful software moving again!

Ok guys – the project is up on git-hub!

Install Git! – http://git-scm.com/

To download an anonymous repository run git clone git://github.com/astubbs/spring-modules.git or sign up with git-hub and get your personal account!

Let the patching begin!

From the Wiki page:

This is a resurrection of the extremely valuable and abandoned Spring-Modules project.

The plan is to fully embrace Maven as the build tool and eventually throw out all the old build code.

At this point, all the old jar libraries and generated documentation have been pruned from the repository history.

This pruning has reduced the size of the repository from 95m to 7m. Nice.

The idea will be to slowly add one by one, as the are compile ready, to the parent module section, so they can be included.

Msg/email me on antony.stubbs@gmail.com to discuss!

I will try and get a development mailing list setup asap, but for now, email me on antony.stubbs@gmail.com with the [subject spring-module-fork] and I’ll start building a manual list. (If anyone knows a free mail list setup, let me know).

One thing I want to discuss is how we can organise the issues on jira :/ I still have had no response from Spring.

P.s.  I’ve also setup a mailing list now:

Mailing List

Here are the essentials:

July 26, 2008

Google Guice – Injecting primitives in constructors

Filed under: Java — Tags: , , , , , , — Antony Stubbs @ 2:10 am

Guice‘s user guide could definitely do with some work. It’s ok in some parts but overall it leaves a lot “up to the imagination” if you know what I mean.

I’d been googling various combinations of the words of the title of this blog post, and the Guice forums but couldn’t find an example or explanation of what I was looking for. I really think the User Guide needs this example in there.

For one thing, they definitely need more usage examples.

For example, they do not clearly show how to inject primitives into an injected constructor! I couldn’t figure it out from reading the user guide, but finally after some very random Google link clicking, I found an example. This post is to help try and bring this example to the fore front for other people to see.

To do this, I have now discovered nearly by fluke:

bindConstant().annotatedWith(Names.named( "dogs  name" )).to("suki");

and then in your constructor for the Guice managed object where the String is to be injected:

@Inject
public HouseHoldPet ( @Named( "dogs name" ) String myDogsName);

Pretty easy really now that I see it. Didn’t really understand the information around the @Named annotation in the user guide, but after seeing this example, I can see how it works.

Of course as far as Guice vs Spring is concerned – you’re *still* left with the task of keeping the key names in sync.

Oh First Class Properties, how I miss thee!

</adam sandler>3 weeks later…</adam sandler>

De’ night time is de’ right time… De’ night time is de’ right time…

Of course, I could have read this from the user guide, a little closer:

// Bind Bar to an instance of Bar.
Bar bar = new Bar();
binder.bind(Bar.class).toInstance(bar);

But there I suppose I was reading too fast, and it wasn’t sooo obvious. Honest.

This of course means that the above, as long as your requirements are pretty basic as mine were, can be replaced with:

bind(Animals.class).toInstance(new HouseHoldPet("suki");

Which would allow me to still have the pet name managed by the module configuration but allow the class to be automatically injected into dependent classes.

The draw back to using this approach is that you’re basically using a singleton. You probably don’t want to do that.

Along with the user guide, the Java Doc for the Binder Interface which I have also just discovered, actually has some other good examples with good explanations. However, the user guide again does not direct you here.

And yes, the 3 weeks later is an Adam Sandler joke 🙂 – it was more like, ‘later that night’… 😉

Update…

I have come across a new blog by Dhanji R. Prasanna which I found in response to my post about this blog on the Guice forum.

One of his blog posts on his thoughts on closures for java, contained a very succinct example of the Provider Interface:

bind(Service.class).toProvider(new Provider<Service>() {
    public Service get() {
        return new ServiceImpl();
    }
});

Using this technique, I can avoid the hassle of building an annotation for my parameter injection:

bind(Animals.class).toProvider(new Provider<Animals>() {
    public Animals get() {
        return new HouseHoldPet( "suki" );
    }
});

Neato!

And if you have a class which doesn’t implement an Interface, as do I, you can still an in-line factory for said class which injects the primitive:

bind(HouseHoldPet.class).toProvider(new Provider<HouseHoldPet>() {
    public HouseHoldPet get() {
        return new HouseHoldPet( "suki" );
    }
});

Choice!

“suki” of course should be extracted to a local constant – something like DEFAULT_PET_NAME or some such.

Create a free website or blog at WordPress.com.