Last updated Jun 13, 2024

First, add Spring’s context namespace to your Spring XML file if it’s not already there. For example:

1
2
<beans
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

Next, register your new config classes in this file in one of two ways:

Option 1

  • Add a <context:annotation-config /> element (to enable the use of @Configuration classes), then
  • add your new Java config class(es) as anonymous beans, for example <bean class="com.example.myplugin.spring.SpringBeans" />.

Option 2

  • Add a <context:component-scan base-package="..." /> element that points to the package containing your new @Configuration classes (this implicitly includes everything that the context:annotation-config element does). In this scenario, it's a good idea to ensure that this package contains only your @Configuration classes, to avoid scanning any classes unnecessarily.

Rate this page: