IntelliJ IDEA 2016.3 Help

Managing Spring Configuration Files

This feature is supported in Ultimate edition only.

Spring configuration files contain bean definitions and other information. They are used to provide context information to the Spring framework.

IntelliJ IDEA lets you manage "traditional" XML configuration files and also @Configuration-annotated Java classes.

Mutually-related configuration files can be arranged in file sets to make their editing more effective.

When working with configuration files in the editor, you can generate beans, properties, dependencies, etc. using the IntelliJ IDEA's code generation feature (Code | Generate or Alt+Insert). You can also analyze the structure of your application using the Spring dependencies diagram.

Creating a New XML Configuration File

  1. In the Project tool window, select the package or directory in which you want to create a configuration file. Then choose File | New or press Alt+Insert.

    Alternatively, right-click the package or directory, and click New.

  2. Select XML Configuration File and then select Spring Config.
  3. In the New File dialog, specify the name of the configuration file and click OK.

    As a result, the new configuration file is created and opened in the editor.

  4. If necessary, add the configuration file to a file set.

Adding an XML Configuration File to a File Set

There are three ways to add an XML configuration file to a file set:

  • Unless an XML configuration file is included in at least one file set, the Configure File Set link is available in the editor for the configuration file. This link is located above the editing area, in the upper-right corner of the corresponding editor tab.
    1. Click the Configure File Set link.
    2. If you haven't defined any XML file sets yet, the Edit Application Context dialog opens. Configure the file set as required and click OK.

      If at least one XML file set already exists, you can add the configuration file to an existing file set or create a new file set and add the configuration file to it. To do that, select the necessary option from the Choose file set menu:

      • To add the configuration file to an existing file set, select the necessary file set.
      • To add the configuration file to a file set that does not yet exist, select <new file set>. Then, in the Edit Application Context dialog, configure the file set and click OK.
  • Click the Create Default Context link in the upper-right corner of the editor tab where the unmapped configuration file is opened:
    /help/img/idea/2016.3/spring_create_default_context_link.png
  • Add a configuration file to a file set by editing the relevant file set as described in Managing File Sets. See also Creating a file set.

Creating a @Configuration-annotated Java Class

The procedure for creating @Configuration-annotated Java classes is the same as for creating "ordinary" classes, see Creating Java Classes, Interfaces, Enumerations and Annotations.

See Also

Last modified: 7 December 2016