Work note summary

Source: Internet
Author: User

1. Common Project Annotations:

Service Layer

Imp: @ Transactional

@ Component ("xxxService ")

Public class xxxService {.....}

Interface:

DAO Layer

@ Repository ("xxxDao ")

@ Autowired

@ Qualifier ("xxxDAO ")

Public class XxxDAO {.....}

 


Meanings of common Annotations:

@ Autowired:


// Spring 2.5 introduces @ Autowired annotation, which can mark class member variables, methods, and constructors to complete automatic assembly. Use @ Autowired to remove the set and get methods.

// Add the following content to applicationContext. xml:

// <! -- The BeanPostProcessor will automatically inject the Bean labeled @ Autowired -->
<Bean class = "org. springframework. beans. factory. annotation. AutowiredAnnotationBeanPostProcessor"/>

@ Qualifier:

Annotation specifies the name of the injected Bean to eliminate the ambiguity. You can solve the exception through the following method.


Combination of the two: XX in @ Qualifier ("XXX") is the Bean name, so when @ Autowired and @ Qualifier are used together, the automatic injection policy is changed from byType to byName.


@ Resource:

The function is equivalent to @ Autowired, but @ Autowired is automatically injected by byType, while @ Resource is automatically injected by byName by default. @ Resource has two attributes, namely name and type. Spring resolves the name attribute of @ Resource annotation to the bean name, And the type attribute to the bean type. Therefore, if the name attribute is used, the automatic injection policy of byName is used, and the automatic injection policy of byType is used when the type attribute is used. If neither name nor type is specified, the byName automatic injection policy is used through reflection.

@ Resource Assembly Sequence
1. If both name and type are specified, a unique matching bean is found in the Spring context for assembly. If no matching bean is found, an exception is thrown.
2. If name is specified, query the bean with the matching name (id) in the context for assembly. If no name is found, an exception is thrown.
3. If type is specified, an exception will be thrown if a unique bean of type matching is found in the context for assembly and no or multiple beans can be found.
4. If neither name nor type is specified, the system automatically performs the Assembly in byName mode. If no match exists, the system returns to an original type for matching. If the match exists, the system automatically assembles the data;

 

 

Starting from version 2.0, Spring uses @ Repository, @ Service, @ Controller, and @ Component to mark the class as Bean:


Enable the scanner in the configuration file

The Code is as follows:


[Html]
<Beans... >
......
<Context: component-scan base-package = "bookstore. dao"/>
...
</Beans>

<Beans... >
......
<Context: component-scan base-package = "bookstore. dao"/>
......
</Beans>
2. General frameworks have default settings

1) Use the FTPClient class under the commons-net package to upload and download folders to and from ftp at a fast speed, but the upload speed is terrible, the default cache value in the source code of jar is 1024 bytes. If buffersize is not set in FTPClient, the cache size in the static variable of the parent FTP is 1024, you only need to call the setBufferSize of FTPClient to increase the cache, reduce the number of I/O operations, and read data in batches, improving the upload efficiency.

 


 

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.