Spring-springMVC3.2 tags

1. If you don't want to configure beans in the xml file, we can add spring component annotations to our classes, and just configure the spring scanner to achieve automatic bean loading.
<!-- Annotation injection-->
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.liantuo.hotel.common.service.impl" />
<context:component-scan base-package="com.liantuo.hotel.common.dao.ibatis" />
<context:component-scan base-package="com.liantuo.hotel.app.dao.ibatis" />
<context:component-scan base-package="com.liantuo.hotel.app.service" />
<context:component-scan base-package="com.liantuo.hotel.app.service.ibatis" />
2. The following is a quote from the spring framework development manual "
Spring 2.5 introduced more stereotype annotations:  @Component , @Service and  @Controller . @Component is the generic form for all Spring-managed components; while @Repository , @Service and  @Controller are @Component refinements used to represent more specific use cases (eg, for persistence, service, and presentation, respectively). That is, you @Component can annotate your component classes with , but if you annotate them with @Repository , @Service  or @Controller , your classes may be better handled by tools, or associated with aspects. For example, these canonicalization annotations can be ideal pointcut targets. Of course, in future versions of the Spring Framework,  @Repository , @Service and  @Controller may carry more semantics. As such, if you are considering whether to use @Component or not in the service layer @Service , it @Service is obviously a better choice. Also, as mentioned earlier,  @Repository it can be used as a marker for exception translation in the persistence layer. "
3. With <context:component-scan>, another <context:annotation-config/> tag can be removed at all, because it is already included.
4. <context:component-scan> provides two sub-tags: <context:include-filter> and <context:exclude-filter>, which represent the imported and excluded filters.
如: <context:component-scan base-package="com.xhlx.finance.budget" >
<context:include-filter type="regex" expression=".service.*"/>
</context:component-scan>
5. The filter tag has five types in Spring 3, as follows:
Filter Type Examples Expression Description
annotation org.example.SomeAnnotation A target class that conforms to SomeAnnoation
assignable org.example.SomeClass Specify the full name of the class or interface
aspectj org.example..*Service+ AspectJ syntax
regex org\.example\.Default.* Controller Expression
custom org.example.MyTypeFilter Spring3 adds a custom Type, implements org.springframework.core.type.TypeFilter

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325710555&siteId=291194637