Spring: support for factory-bean/method broken?

I get lots of errors in my context files when beans defined as being created
using a factory bean/method, see the following snippet:

]]>

1. init-method is highlighted in red for those beans that define it (the type
information seems to be lost when using factory method/bean) and the
error message shown is 'Cannot resolve symbol 'symbol'';

2. the value of factory-method is highlighted in red and the error states that
'No matching factory method found in class 'Object''. Where does it get that
from? Both the factory and the bean have classes defined.

3. No property within the bean definition is recognised as if the bean is of type
Object

Anyone knows how to fix that? Are these bugs in IDEA or in IDEA Spring?

Cheers,

Bonny

10 comments
Comment actions Permalink

Your classes should look like that:

public class FactoryClass {
public BeanClass createInstance() {
return new BeanClass();
}
}

public class BeanClass {
public void configComplete() {
}
}

are they? Which Selena build are you using?


0
Comment actions Permalink

Hello Bonny,

Are you using Selena EAP or IDEA 6.0+IdeaSpring plugin?

-tt


0
Comment actions Permalink

Dmitry,

No, the factory method on the factory class does not have this signature,
simply because the factory is able to create instances of multiple types.

I would have thought that given the type is provided in the bean definition,
IDEA could use that to determine things like properties, etc.

This is in build 6963.

Cheers,

Bonny

0
Comment actions Permalink

The build number is actually 6981, not 6963.

Cheers,

Bonny

0
Comment actions Permalink

Hello Bonny,

I think IDEA expects (or should expect) either "factory-bean" or "class"
attribute, but not both.
The spring manual describes the functionality in similar terms (3.2.3.2.3):
--
(about using "factory-bean")
To use this mechanism, the 'class' attribute must be left empty, and the
'factory-bean' attribute must specify the name of a bean in the current (or
parent/ancestor) container that contains the factory method. The factory
method itself must still be set via the 'factory-method' attribute (as seen
in the example below).
--

Do you have a complete example (including Java source)?

-tt


0
Comment actions Permalink

Taras,

You're right about Spring, my bad, although your'e supposed to be able to
programatically get a bean with a specific type (and get Spring to barf if the
resulting bean does not match the type) using the getBean(String, Class)
variant. Perhaps I should suggest it over at the Spring forums.

My use case involves using combination of reflection and spring configuration
and so the FactoryFactory 'concept' was chosen. This of course forced the
factory to widen the return type scope and IDEA is right to behave the way it does,
although it would be nice if it used the class attribute (Spring does not mind it being
there).

Cheers,

Bonny

0
Comment actions Permalink

This is in fact a lack of custom bean factories support in IDEA.
I've created two issues for this:
http://www.jetbrains.net/jira/browse/IDEADEV-17672
http://www.jetbrains.net/jira/browse/IDEADEV-17673


0
Comment actions Permalink

Hello Bonny,

My use case involves using combination of reflection and spring
configuration
and so the FactoryFactory 'concept' was chosen. This of course forced
the
factory to widen the return type scope and IDEA is right to behave the
way it does,
although it would be nice if it used the class attribute (Spring does
not mind it being
there).


Perhaps, but a future version of spring could easily start validating and
rejecting such a construct, I think.

I think there are two alternatives in your scenario:
1) Implement InitializingBean and/or DisposableBean in the class that your
factory produces.
2) Use a base class for the "products" of your factory. This class would
have empty init()/destroy() methods.
Actual product classes would override these methods where applicable.

-tt


0
Comment actions Permalink

Taras,

Thanks for your suggestions. In other circumcstances that is what I do.
However, in this situation, there are enough beans requiring both Spring-time
and app run-time configuration, and they are of different hierarchies to warrant
the solution I've chosen. It works well.

The only issue is IDEA's redlighting of these constructs (as it is its right given
the spec) during editing.

Also wrt Spring, if it was to start validating these constructs, it would make
it more explicit and better for tools like IDEA, but I do not think that it will be
made to reject this approach. Do you know which version these validation
rules are planned for (I'll head over there and check current chat in the forums, too)?

Cheers,

Bonny

0
Comment actions Permalink

Hello Bonny,

Thanks for your suggestions. In other circumcstances that is what I
do. However, in this situation, there are enough beans requiring both
Spring-time and app run-time configuration, and they are of different
hierarchies to warrant the solution I've chosen. It works well.

The only issue is IDEA's redlighting of these constructs (as it is its
right given the spec) during editing.

Also wrt Spring, if it was to start validating these constructs, it
would make
it more explicit and better for tools like IDEA, but I do not think
that it will be
made to reject this approach. Do you know which version these
validation
rules are planned for (I'll head over there and check current chat in
the forums, too)?
Cheers,


There are no such plans AFAIK. I meant to write that a future version could
start validating/rejecting this.

By the way, I think IDEA supports switching off specific inspections for
sections of, or whole documents.
Perhaps that can be useful to you, although it introduces an IDEA-specific
comment into your configuration file.

Regards,
-tt


0

Please sign in to leave a comment.