Specifying base package in spring xml config file

Instead of using @ComponentScan annotation, we can also use <context:component-scan> element in an spring config xml.

spring.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <context:component-scan base-package="com.javajee.spring" />

</beans>

You then need to use ClassPathXmlApplicationContext to get the context:

ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!