Table of Contents
1、Maven
3、引入Spring并配置" >3、引入Spring并配置
Home Database Mysql Tutorial 为Eclipse上的Maven project添加SpringMVC和Mybatis以实现数据库

为Eclipse上的Maven project添加SpringMVC和Mybatis以实现数据库

Jun 07, 2016 pm 02:50 PM
eclipse maven project sp Add to

背景 工作中要实现跨数据库的package调用,在jsp前端返回,目前项目上只是Maven,所以参照Andyの笔记来看看结合自己所在项目都需要哪些更新来实现一个简单的功能。 1、Maven 虽然项目中已经在Eclipse中嵌入了Maven,但还是可以单独安装一个Maven的工具在系统

背景

工作中要实现跨数据库的package调用,在jsp前端返回,目前项目上只是Maven,所以参照Andyの笔记来看看结合自己所在项目都需要哪些更新来实现一个简单的功能。

1、Maven

虽然项目中已经在Eclipse中嵌入了Maven,但还是可以单独安装一个Maven的工具在系统中,参考Andy的Maven环境搭建和介绍 来操作即可。

中间遇到了问题“-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.”,可以在这里解决。

2、Generate Mybatis

加载完dependence之后,按Andy的Mybatis使用generator自动生成映射配置文件信息交待生成配置文件。其中正确生成了BxxxxxLxxxx.java,BxxxxxLxxxxMapper.java 以及BxxxxxLxxxxMapper.xml,分别放在\src\main\java\com\xxxxx\xxx\domain,src\main\java\com\xxxxx\xxx\mapper以及src\main\java\com\xxxxx\xxx\mapper\sqlmaps目录下。

3、引入Spring并配置

按照步骤提示继续,针对即将新引入的jar包,更改pom.xml文件

        <!-- spring add by Steven -->
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-core</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-beans</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-context</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-tx</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-web</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-webmvc</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-jdbc</artifactid>  
            <version>3.1.1.RELEASE</version>  
        </dependency>
        <dependency>  
            <groupid>org.springframework</groupid>  
            <artifactid>spring-test</artifactid>  
            <version>3.1.1.RELEASE</version>  
            <scope>test</scope>  
        </dependency>
        <!-- mybatis add by Steven -->
        <dependency>  
            <groupid>org.mybatis</groupid>  
            <artifactid>mybatis</artifactid>  
            <version>3.1.0</version> 
        </dependency>
        <!--mybatis spring add by Steven -->  
        <dependency>  
            <groupid>org.mybatis</groupid>  
            <artifactid>mybatis-spring</artifactid>  
            <version>1.1.1</version>
        </dependency>
        <!--log4j add by Steven -->  
        <dependency>  
            <groupid>log4j</groupid>  
            <artifactid>log4j</artifactid>  
            <version>1.2.17</version>
        </dependency>
        <!-- struts2 add by Steven -->
        <dependency>
	        <groupid>org.apache.struts</groupid>
	        <artifactid>struts2-core</artifactid>
	        <version>2.3.16.3</version>
        </dependency>
        <dependency>
	        <groupid>org.apache.struts</groupid>
	        <artifactid>struts2-json-plugin</artifactid>
	        <version>2.3.16.3</version>
        </dependency>
        <dependency>
	        <groupid>org.apache.struts</groupid>
	        <artifactid>struts2-spring-plugin</artifactid>
	        <version>2.3.16.3</version>
        </dependency>
        <!-- Gson add by Steven -->
        <dependency>
            <groupid>com.google.code.gson</groupid>
            <artifactid>gson</artifactid>
            <version>2.1</version>
        </dependency>
        <!-- c3p0 add by Steven -->
        <dependency>
            <groupid>com.mchange</groupid>
            <artifactid>c3p0</artifactid>
            <version>0.9.5</version>
        </dependency>
        <!-- aspectjweaver add by Steven -->
        <dependency>
	        <groupid>org.aspectj</groupid>
	        <artifactid>aspectjweaver</artifactid>
	        <version>1.6.8</version>
        </dependency>
        <!-- cglib add by Steven -->
        <dependency>
	        <groupid>cglib</groupid>
	        <artifactid>cglib</artifactid>
	        <version>2.2.2</version>
        </dependency>
...
        <resources>
         <resource>        
                 <directory>src/main/resource</directory>
           <includes>
              <include>*.xml</include>
              <include>*.properties</include>
           </includes>
             </resource>
     </resources> 
Copy after login
以及需要在build节点里加入以下resources引用,以帮助Maven加载需要的struts和myBatisConfig的配置文件。



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add a TV to Mijia How to add a TV to Mijia Mar 25, 2024 pm 05:00 PM

Many users are increasingly favoring the electronic ecosystem of Xiaomi smart home interconnection in modern life. After connecting to the Mijia APP, you can easily control the connected devices with your mobile phone. However, many users still don’t know how to add Mijia to their homes. app, then this tutorial guide will bring you the specific connection methods and steps, hoping to help everyone in need. 1. After downloading Mijia APP, create or log in to Xiaomi account. 2. Adding method: After the new device is powered on, bring the phone close to the device and turn on the Xiaomi TV. Under normal circumstances, a connection prompt will pop up. Select &quot;OK&quot; to enter the device connection process. If no prompt pops up, you can also add the device manually. The method is: after entering the smart home APP, click the 1st button on the lower left

Java Maven build tool advancement: optimizing compilation speed and dependency management Java Maven build tool advancement: optimizing compilation speed and dependency management Apr 17, 2024 pm 06:42 PM

Optimize Maven build tools: Optimize compilation speed: Take advantage of parallel compilation and incremental compilation. Optimize dependencies: Analyze dependency trees and use BOM (bill of materials) to manage transitive dependencies. Practical case: illustrate optimizing compilation speed and dependency management through examples.

Avoid common mistakes in Maven environment configuration: Solve configuration problems Avoid common mistakes in Maven environment configuration: Solve configuration problems Feb 19, 2024 pm 04:56 PM

Maven is a Java project management and build tool that is widely used in the development of Java projects. In the process of using Maven to build projects, you often encounter some common environment configuration problems. This article will answer these common questions and provide specific code examples to help readers avoid common configuration errors. 1. Maven environment variables are incorrectly configured. Problem description: When using Maven, if the environment variables are incorrectly configured, Maven may not work properly. Solution: Make sure

How to add a new script in Tampermonkey-How to delete a script in Tampermonkey How to add a new script in Tampermonkey-How to delete a script in Tampermonkey Mar 18, 2024 pm 12:10 PM

Tampermonkey Chrome extension is a user script management plug-in that improves user efficiency and browsing experience through scripts. So how does Tampermonkey add new scripts? How to delete the script? Let the editor give you the answer below! How to add a new script to Tampermonkey: 1. Take GreasyFork as an example. Open the GreasyFork web page and enter the script you want to follow. The editor here chooses one-click offline download. 2. Select a script. , after entering the script page, you can see the button to install this script. 3. Click to install this script to come to the installation interface. Just click here to install. 4. We can see the installed one-click in the installation script.

Outlook stuck on adding account [Fixed] Outlook stuck on adding account [Fixed] Mar 23, 2024 pm 12:21 PM

When you encounter problems adding accounts in Outlook, you can try the following solutions to resolve it. Typically this can be caused by a faulty network connection, corrupted user profiles, or other temporary issues. Through the methods provided in this article, you can easily solve these problems and ensure that your Outlook can run normally. Outlook stuck on adding account If your Outlook is stuck on adding account, then use these fixes mentioned below: Disconnect and reconnect the internet Temporarily disable antivirus software Create a new Outlook profile Try adding account in safe mode Disable IPv6 Run Microsoft Support and Recovery Assistant Repair Office Application Outlook Add Account Required

Common ways to add elements to Java arrays Common ways to add elements to Java arrays Feb 21, 2024 am 11:21 AM

Common ways to add elements to Java arrays, specific code examples are required In Java, an array is a common data structure that can store multiple elements of the same type. In actual development, we often need to add new elements to the array. This article will introduce common methods of adding elements to arrays in Java and provide specific code examples. A simple way to create a new array using a loop is to create a new array, copy the elements of the old array into the new array, and add the new elements. The code example is as follows: //original array i

Basic tutorial: Create a Maven project using IDEA Basic tutorial: Create a Maven project using IDEA Feb 19, 2024 pm 04:43 PM

IDEA (IntelliJIDEA) is a powerful integrated development environment that can help developers develop various Java applications quickly and efficiently. In Java project development, using Maven as a project management tool can help us better manage dependent libraries, build projects, etc. This article will detail the basic steps on how to create a Maven project in IDEA, while providing specific code examples. Step 1: Open IDEA and create a new project Open IntelliJIDEA

Detailed explanation of Maven Alibaba Cloud image configuration Detailed explanation of Maven Alibaba Cloud image configuration Feb 21, 2024 pm 10:12 PM

Detailed explanation of Maven Alibaba Cloud image configuration Maven is a Java project management tool. By configuring Maven, you can easily download dependent libraries and build projects. The Alibaba Cloud image can speed up Maven's download speed and improve project construction efficiency. This article will introduce in detail how to configure Alibaba Cloud mirroring and provide specific code examples. What is Alibaba Cloud Image? Alibaba Cloud Mirror is the Maven mirror service provided by Alibaba Cloud. By using Alibaba Cloud Mirror, you can greatly speed up the downloading of Maven dependency libraries. Alibaba Cloud Mirror

See all articles