Java Reference
In-Depth Information
<context:exclude-filter type=" annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
</beans>
Because you have applied include filters to detect all classes whose name contains the word Dao or
Service , the SequenceDaoImpl and SequenceService components can be auto-detected even without a
stereotype annotation.
Naming Detected Components
By default, Spring will name the detected components by lowercasing the first character of the non-
qualified class name. For example, the SequenceService class will be named as sequenceService . You can
define the name for a component explicitly by specifying it in the stereotype annotation's value.
package com.apress.springenterpriserecipes.sequence;
...
import org.springframework.stereotype.Service;
@Service(" sequenceService")
public class SequenceService {
...
}
package com.apress.springenterpriserecipes.sequence;
import org.springframework.stereotype.Repository;
@Repository(" sequenceDao")
public class SequenceDaoImpl implements SequenceDao {
...
}
You can develop your own naming strategy by implementing the BeanNameGenerator interface and
specifying it in the name-generator attribute of the <context:component-scan> element.
1-6. Setting Bean Scopes
Problem
When you declare a bean in the configuration file, you are actually defining a template for bean creation,
not an actual bean instance. When a bean is requested by the getBean() method or a reference from
other beans, Spring will decide which bean instance should be returned according to the bean scope.
Sometimes you have to set an appropriate scope for a bean other than the default scope.
 
Search WWH ::




Custom Search