How to configure Spring using Annotation?

Solution

By default, Annotation wiring is not turned on in the Spring container. So, before you can use annotation-based wiring, you need to enable it in your Spring configuration file. Using <context:annotation-config> you can enable annotation in your Spring application.
Example:

<?xml version="1.0" encoding="UTF-8"?>
                         <beans xmlns="http://www.springframework.org/schema/beans"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xmlns:context="http://www.springframework.org/schema/context"
                          xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-3.0.xsd">

                          <context:annotation-config/>
                          <!-- bean definitions go here -->

                        </beans>

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media