Listing 4-16. Spring XML Configuration Component Scan
<context:component-scan base-package="com.apress.prospring3.ch4.annotation" >
<context:exclude-filter type="assignable" expression="com.example.NotAService"/>
</ context:component-scan>
The previous tag tells Spring to scan the package as specified but omit the classes that were assignable
to the type as specified in the expression (can be either a class or an interface). Besides the exclude filter,
you can also use an include filter. And for the type, you can use annotation, regex, assignable, AspectJ, or
custom (with your own filter class that implements org.springframework.core.type.filter.TypeFilter)
as the filter criteria. The expression format depends on the type you specified.
Declare Spring Components
After you develop some kind of service classes and want to use it in a Spring base application, you need
to tell Spring that those beans are eligible for injection to other beans and have Spring manage them for
you. Consider the sample in Chapter 2, where the MessageRender outputs the message and depends on
the MessageProvider to provide the message to render. Listing 4-17 recaps the interfaces and
implementations of the two services.
Listing 4-17. MessageRenderer and MessageProvider
package com.apress.prospring3.ch4;
public interface MessageRenderer {
public void render();
public void setMessageProvider(MessageProvider provider);
public MessageProvider getMessageProvider();
}
package com.apress.prospring3.ch4.xml;
import com.apress.prospring3.ch4.MessageProvider;
import com.apress.prospring3.ch4.MessageRenderer;
public class StandardOutMessageRenderer implements MessageRenderer {
private MessageProvider messageProvider = null;
public void render() {
if (messageProvider == null) {
throw new RuntimeException(
"You must set the property messageProvider of class:"
+ StandardOutMessageRenderer.class.getName());
}
System.out.println(messageProvider.getMessage());
}
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home