Spring MVC 3.0.5 + Spring 3.0.5 + MyBatis3.0.4 full annotation Example 1

Source: Internet
Author: User
Tags maven central

After Spring is updated to 3.0, the MVC Framework adds a very good thing-REST. Its open architecture, seamless integration with Spring, and outstanding performance of the Spring framework make it a new system development framework. Based on the actual project experience and the previous SSH2 example, the elephant made a major transformation and explained in detail how to implement SSM3 full-annotation development.

This time, the elephant will adopt two construction methods: MyEclipse, which many prefer, and Eclipse + Maven. This article mainly describes how to configure the development environment and build Maven.
1. Development Environment
JDK1.6.0 _ 18
Eclipse3.2.1 MyEclipse5.1.0
Eclipse-JEE-HELIOS-SR2 Maven3.0.1 m2eclipse0.12.1.20110112-1712
Tomcat6.0.10 maven-jetty-plugin6.1.26
MySQL5.0.27 Navicat Lite for MySQL 8.1.20
Each person's development environment may be different, but one thing I need to note is that the JDK version cannot be lower than 1.5, because many new features supported by version 1.5 are used. Tomcat, Jetty, Maven, and MySQL versions should not be lower than the ones I use, because I did not test them in other versions. Navicat is a graphical operation tool for MySQL databases. Next, I will introduce how to use the m2eclipse plug-in Eclipse3.6 to build a web application and test the development environment.

2. Set Maven
Maven installation is simple. You only need to decompress it. Set the PATH variable so that you can use the command line to perform the operation. Then, modify settings. xml in the % MAVEN_HOME % conf directory.

This is to set the local repository. The directory can be changed according to your actual situation. However, please use a forward slash (/), because in actual use, I found that the backslash sometimes cannot obtain resources. For personal use, it is okay to set this. As for Nexus configuration, it is not covered in this article. If you are interested, you can go to juven xu's blog. He is currently recognized as a Maven expert.
3. Install m2eclipse
Select Help-> Install New Software... in the pop-up window, click Add... and a small window will pop up. Enter the installation address of m2eclipse, as shown in:

After entering the information, clickOK.EclipseNow you can find this plug-in. Please wait for a while.

After the plug-in is found, check the content to be installed. The general installation process is followed, and 500 words are omitted here. After the installation is complete, restart Eclipse and set the plug-in.
4. Set m2eclipse
Go to Perferences, select Maven, and remove the check box before Download repository index updates on startup. By default, the index is automatically downloaded from the Maven central repository each time Eclipse is started, this is undoubtedly very bad. You need to know that the jar resources contained in the Maven central repository are very large, and many new projects are uploaded every day, so Eclipse is not ready for use, it's just getting rid of these things.

Next, select Installations to replace the Maven that comes with this plug-in with the installed Maven, which ensures version consistency.

After setting this, click User Settings and use the settings of maven on the local machine. xml replaces the default configuration file, because the default setting is to place the local repository to the system drive letter Documents and Settings user directory \. under the m2epository directory.

As you can see, after the configuration file in maven is replaced, the Local Repository below is automatically changed to settings. xml.

5. Create a maven Project
After that, we can start creating a Maven project. Select New-> other...-> Maven Project, and then select next

Set the workspace path. Put the default Workspace of the elephant under the root directory of eclipse. The Location here should be empty. For instructions, the path is displayed. Click Next>

This List displays all the Project Creation types supported by maven. We are developing web applications. Therefore, select maven-archetype-webapp.

The last step is to enter the project we want to create. In the Maven world, coordinates are used to uniquely identify a component, which can be understood as a project or a resource. Group Id indicates the actual project to which the current project belongs. Artifact Id defines a Maven project in the actual project. It can be seen by name that Group Id is a large range, the Artifact Id is a small range. For example, we are very familiar with spring, is divided into spring-core.jar, spring-beans.jar, spring-context.jar and so on. In maven, the Group Id is org. springframework, while the Artifact Id is spring-core, spring-beans, and spring-context. How is it? Understand?
At this point, the project is generated. Expand src/main, create a new java folder under the main directory, and open the Project Properties of ssm3, select Java Build Path-> Source-> Add Folder... -> check java to use the src/main/java path as the folder of the source file, which is different from the directory structure developed using MyEclipse. Maven rules are also defined in this way. If you do not perform this setting, even if you create a java directory under main and then add a package or class, there will be problems. Let's try it, see what errors will occur.

 

6. Run ssm3
Next, add the maven-jetty-plugin plug-in to the pom. xml file. The default configuration can be removed, and only the configuration shown in the pom file is used.

Open Run invocations, which can be opened in multiple ways. You can choose from the Run menu, select from the toolbar, or right-click the project.

In the pop-up window, set the running parameters in Maven Build, Click Browse Workspace... the small window will pop up, set Base directory, add jetty: run, and click Run To start jetty.

 

 

 

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.