Home Tutorial Spring Spring3 Ioc Excluding filter in Spring


Share on Google+Share on Google+
Excluding filter in Spring
Posted on: September 2, 2010 at 12:00 AM
In this tutorial you will learn about how to exclude specified component in spring framework.

Exclude-Filter in Spring

In this tutorial you will learn about how to exclude specified component, if you want spring to avoid detection and inclusion  into the spring container exclude those files with the @Service annotation


package com.roseindia.student.dao;

import org.springframework.stereotype.Service;

public class StudentDAO {
	public String toString() {
		return " Inside StudentDAO";

StudentService .java

package com.roseindia.student.services;

import org.springframework.stereotype.Service;

import com.roseindia.student.dao.StudentDAO;

public class StudentService {

	StudentDAO studentDAO;

	public String toString() {
		return "StudentService [studentDAO=" + studentDAO + "]";

AppMain .java

package com.roseindia.common;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.roseindia.student.services.StudentService;

public class AppMain {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "context.xml" });
		StudentService stud = (StudentService) context


<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"

  <context:component-scan base-package="com.roseindia">

    <context:include-filter type="regex"
      expression="com.roseindia.student.services.*Service.*" />

    <context:exclude-filter type="regex"
      expression="com.mkyong.customer.dao.*DAO.*" />


The same can be done through this code also  
  <context:component-scan base-package="com.roseindia" >
  <context:exclude-filter type="regex" 
                 expression="com.roseindia.student.dao.*DAO.*" />


When you run this application it will display message as shown below:

StudentService [studentDAO=null]

Download this example code


Related Tags for Excluding filter in Spring:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 2, 2010

Recommend the tutorial

Advertisements Advertisements