A classic springMVC annotation Implementation Method

Source: Internet
Author: User

 

Today, the company asked me to build a springMVC annotation framework for a long time. I searched the network for a long time and found an article. I 'd like to share it with you:

Source: http://www.itxxz.com/a/kuangjia/2014/0531/4.html

Hello everyone, I amIT learnersCrab, I wrote a spring MVC annotation instance two days ago. At present, it seems that there are already a large number of people downloading and there are also many people who have some questions about the configuration, here, crab gives a detailed description of the spring configuration in that instance, which is regarded as a comprehensive analysis of the spring annotation mode.

The spring configuration in the instance is very simple and practical. After all, we started from setting up the framework and haven't integrated other advanced applications, so the content is slightly less. Therefore, it has become the best entry material for spring annotation mode.

Let's first look at a picture.


We can see that the main configuration file applicationContext. xml of spring is only one hundred, and several required beans are configured, and then the configuration file can be loaded when the project starts. If you cannot see the source code of the instance clearly in the figure, you can see the download page link at the end of the file.

The configuration for enabling annotation in spring is as follows:

<! -- Enable automatic scanning --> <context: annotation-config/> <context: component-scan base-package = "com. itxxz "use-default-filters =" false "> <context: include-filter type =" annotation "expression =" org. springframework. stereotype. service "/> <context: include-filter type =" annotation "expression =" org. springframework. stereotype. repository "/> <context: include-filter type =" annotation "expression =" org. springframework. stereotype. component "/> </context: component-scan>


1. First, specify the package path (base-package = "com. itxxz"), that is, the Directory of dao, service, controller (or action) in the project.

In fact, there are only three instance layers written by crabs. dao is an interface and no implementation class is defined (the cause will be explained later ). The service is used to process the business logic, while the controller layer only acts as the view control forwarding.

2. Enable annotation, that is, the Service, Repository, and Component statements in the preceding configuration. The following code details:


Dao Layer 
Service Layer

Controller Layer
 

 


So far, the spring configuration has come to an end. Next we will explain how spring integrates mybatis, and strive to achieve the most sound implementation through the simplest configuration.

I think there may also be a lot of inactive minds that cannot be reached. According to the above configuration, what error is reported during the operation ?!

Here, the crab reminds me of the following points:

A. Check whether the xml file in the project is configured according to the instance and whether it has been loaded.

B. Whether annotations are added to each layer, and check whether the repository of the dao layer should be written into the resource

C. The dao, service, and controller layers in java code do not inherit other classes or implement other interfaces, especially for SQL

D. Check whether the sqlSessionFactory configured in applicationContext. xml is correctly configured.


For the source code of this instance, you can go 《Spring MVC annotation examples and instructionsDownload, any questions can be fed back to us, we will try to take time to answer.

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.