Spring Bean Wizard?

Given that I already have a Java class defined, is there a way to simply drag and drop that class definition to the bean context xml file or some other way to get the bean definition in the xml file without having to type in everything?

Some type of bean wizard would be nice, but I can't find anything like that in version 11.

Thanks in advance.

-- m

3 comments
Comment actions Permalink

You will find that in IDEA most code generation, quick intentions, and "wizzards" are keyboard based. Not mouse based. So while there is no drag and drop way (that I am aware of) to create a Spring Bean definition, there are a couple of easy peasy ways to create bean definitions.

From the Spring Context Definition
1) In the spring context file, open the code generation popup: Alt+Insert on Windows/Linux, ⌃↩,⌃N on Mac, or Code > Generate from the menu
2) Select "Spring Bean" from the menu
3) IDEA will create a bean element entry. You then have code completion for the various values. It will start in the 'class' attribute. Use Code complete (Ctrl+Space / ⌃Space)  to select your class. You have all the normal code completion short cuts including Camel Case searching. For example, to create a bean definition for MyFancyDancySpringBean, I can simply type Ctrl+Space, MFDSB, enter. You will also have code completion for the id.
4) After completing the class and id attributes, the cursor will be in the bean definition, open the generate menu again (Alt+Insert on Windows/Linux, ⌃↩,⌃N on Mac, or Code > Generate from the menu) and select "Properties". A dialog will open from which you can select the properties you want to wire. select the ones you want and hit enter.
5) Again you will have full code complete, including to other bean references with type awareness.


screenshot.png

From the class
If I am working in a class, I can create a setter dependency. For example, if my spring context is this:

<beans . . .>
    <bean id="serviceUrl" >
        <constructor-arg value="http://example.com/foo" />
    </bean>
</beans>


And I am working in a class "SampleBean". Notice that "SampleBean" is not yet in the spring config. I can open the generate menu (Alt+Insert on Windows/Linux, ⌃↩,⌃N on Mac, or Code > Generate from the menu) and select "Setter Dependency". I will then get a popup showing all the beans that are currently defined. I can select one or more beans that I want to inject and hit enter. IDEA creates the bean definition for my "SampleBean" class complete with all the necessary <properties> element(s). If my class already has a setter for the type of the dependency I am creating a setter dependency for, it uses that. If not, IDEA prompts me to create a setter.

0
Comment actions Permalink

Wow, Mark, thanks very much for this TERRIFIC reply. :) :)

Your posting was incredibly helpful.

Thanks!

-m

0
Comment actions Permalink

Hi,
another way to add bean dependencies is to use diagram(Idea12) http://www.screenr.com/bju8
SV

0

Please sign in to leave a comment.