called after the class is instantiated, and the method that labels the @PreDestroy is called before the class is destroyed.6. @Component annotations (deprecated)Just add a @component annotation to the corresponding class and define the class as a bean. Spring also provides a more granular form of annotations: @Repository, @Service, @Controller, which correspond
Blog Original: http://www.cnblogs.com/xdp-gacl/p/3495887.htmluse annotations to construct an IOC container with annotations to register beans with the spring container. Need to register in Applicationcontext.xml Package= "pagkage1[, Pagkage2, ..., Pagkagen]"/>. Such as: in base-package indicates a packet Package= "Cn.gacl.java"/>indicates the Cn.gacl.java package and its child packages, if a class has a specific a
@respository annotation is used on a presentation layer controller component and does not produce any errors.So @respository, @Service, @Controller These annotations are just for the developer to clarify the role that the current component plays.1.3 Scanning componentsComponents are identified by the above annotations and need to be scanned by spring to be able
Spring MVC series (iii) spring + springMVC integration (annotation Mode)
I personally think that it is not very difficult to use the framework. The key is to understand its ideas, which is very helpful for us to improve programming. However, if you don't use it, you can talk about your thoughts on paper !!! First technology, then thinking. Practice.
1. Basic Con
Inject service with annotation in static tool class, tool class service
It is feasible to directly use the service in the Controller and encapsulate the service as a tool class before calling an error because the service cannot be
@resource annotation to the bean's name, and the type attribute to the Bean's. So if you use the Name property, you use the ByName Auto-injection policy, and the Type property uses the Bytype auto-injection policy. If neither name nor the type attribute is specified, the ByName auto-injection policy is used through the reflection mechanism.@Resource Assembly Order1. If name and type are specified at the same time, the uniquely matched bean is found f
= "success", location = "/success. jsp "), @ Result (name =" input ", location ="/index. jsp ")})Public String execute () throws Exception {// TODO Auto-generated method stubSystem. out. println ("biz:" + this. biz. hashCode ());User u = biz. login (this. getUser ());If (u! = Null ){Return SUCCESS;}Return INPUT;}}@ Component has an optional input parameter used to specify the Bean name. In general, beans are all singleton. To inject beans, you only need to use the byType policy to automatically
Spring does not adopt a policy that is better than the configuration, and spring requires that a Java file be displayed with the specified search path. Spring will register all the appropriate Java classes as spring beans.question: How does spring know which Java classes are
Spring (12)-Bean Injection Using Annotation
In the previous blog posts, bean injection is configured in xml, and Boyou's requirements are added, so we decided to give a simple explanation of the annotation method, it won't involve too complex programs here, because the purpose of this article is to let the majority of bloggers who see this blog post understand it
; } PublicInteger getage () {returnAge ; } Public voidsetage (Integer age) { This. Age =Age ; } PublicCar Getcar () {returncar; } Public voidSetcar (car car) { This. Car =car; }}The same will not do explain, say a few of the following@Resource (name= "car")//This is the annotation under the Javax package, can realize the injection of domain properties, there is another way,@AutoWried@Qualifier (value= "car")//These two lines are used,
Spring provides automatic registration of bean definitions by scanning special annotation classes in the classpath. As with annotation-driven transactions, you need to turn on automatic scanning and register bean definition support in the following ways (Resources/chapter12/componentdefinitionwithannotation.xml):
Java code: Java code
The
The on "
information to really work, you must let the processor responsible for processing the metadata work.And what we've described earlier AutowiredAnnotationBeanPostProcessor CommonAnnotationBeanPostProcessor is the processor that handles these annotation metadata. But defining these beans directly in the Spring configuration file looks awkward. Spring provides us wi
: Injection keyword description@Repository, @Service, @Controller, and @Component identify a class as a bean@Repository annotations belong to the first batch introduced, which identifies the class of the data Access layer (DAO layer ) as a Spring Bean. Just label the note on the DAO class. Also, in order for Spring to be able to scan classes in the Classpath and
Spring does not adopt a policy that is better than the configuration, and spring requires that a Java file be displayed with the specified search path. Spring will register all the appropriate Java classes as spring beans.question: How does spring know which Java classes are
the role of spring @component
1, @controller Controller (injection service)
2, @service Service (injected DAO)
3, @repository DAO (Implementing DAO Access)
4, @component (Instantiate the normal pojo into the spring container, which is equivalent to the
@Component, @
java.math.bigdecimal;import Java.util.arraylist;import Java.util.Date;import Java.util.list;import Java.util.set;public class Demotest {public static void main (string[] args) {Stu Dent xiaoming = Getbean (); ListApplications in 2.SpringMVC:The annotation of the entity class is the same as the student class, but the controller will need to make some changes when it is connected to the value:// 使用@Valid 表明获取到的数据模型需要验证,传入的Errors对象
-notifications, exception notifications, and post-meal notifications. It's okay if we don't write them all in our actual writing, I used to write the logging logic in the Post-notification. I think there are some pre-notifications on the Internet, but I feel it is better to write them in the post-notification.
Add custom annotations to the controller !!
Package com. gcx. controller; import org. springframework. beans. factory. annotation. autowired; i
configurations of Spring 3.0 and MyBatis 3.0. The plug-in must run in JDK 5.0 or later.
V. Service
In the ssm3 example, have you found that no dao is defined for each entity, but MyBatisDao is called as the storage service interface in a unified manner. In addition, the main difference with Hibernate is that an object parameter cannot be directly transmitted,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.