一、   概要说明

最近几天在测试Spring3.0的AOP功能,在测试功能之前,首先是要搭建出Spring3.0的开发功能。开始去官网下载Spring的相关jar包,但是这些jar包中还是会需要其他的一些jar包,于是又手动的去下载其他的相关jar包。这样也可以搭建出开发环境,但是需要频繁的去下载缺少的jar包,很麻烦。这里,我们可以还有一个更好的办法,采用maven来管理我们的工程,让maven来自动为我们去下载相关版本的jar包,具体的配置如下。

二、   下载并安装maven

去网上下载maven安装文件,我这里使用的版本是3.0.1,具体的下载和安装这里不做详细介绍。

三、   搭建Spring开发环境

1. 下载maven插件

要在eclipse中能够正确使用maven工具来构建工程,需要eclipse中已经正确下载安装了maven插件。

2. 编写pom.xml

在工程的根目录中新建一个名为“pom.xml”的文件,在文件中添加如下代码,保存后eclipse会自动下载相关jar包,红色部分为下载相关jar包的xml配置。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>TRSEKP</groupId>

    <artifactId>TRSEKP-V6.6</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <name>TRSEKP-V6.6</name>

    <description>TRSEKP V6.6测试工程</description>

    <properties>

    <project.build.sourceEncoding>GBK</project.build.sourceEncoding>

    </properties>

    <dependencies>

        <!-- 引入Spring-AOP等相关Jar -->

        <dependency> 

            <groupId>org.springframework</groupId> 

            <artifactId>spring-core</artifactId> 

            <version>3.0.6.RELEASE</version> 

        </dependency> 

        <dependency> 

            <groupId>org.springframework</groupId> 

            <artifactId>spring-context</artifactId> 

            <version>3.0.6.RELEASE</version> 

        </dependency> 

        <dependency> 

            <groupId>org.springframework</groupId>

            <artifactId>spring-aop</artifactId> 

            <version>3.0.6.RELEASE</version> 

        </dependency> 

        <dependency> 

            <groupId>org.springframework</groupId> 

            <artifactId>spring-orm</artifactId> 

            <version>3.0.6.RELEASE</version> 

        </dependency> 

        <dependency>

            <groupId>org.aspectj</groupId>

            <artifactId>aspectjrt</artifactId>

            <version>1.6.1</version>

        </dependency>

        <dependency>

            <groupId>aspectj</groupId>

            <artifactId>aspectjweaver</artifactId>

            <version>1.5.3</version>

        </dependency>

    </dependencies>

</project>

 

3. 编写测试类

在eclipse中新建一个测试类,如“com.trs.components.mgr”,具体的代码如下:

package com.trs.components.mgr;

import com.trs.components.persistent.Student;

public class StudentMgr implements IStudentMgr {

    public Student saveOne(String _sName) throws Exception {

        System.out.println("保存了一个学生对象..");

        return null;

    }

    public void saveMany(String _sName) throws Exception {

        System.out.println("保存了多个学生对象..");

    }

}

 

4. 配置bean的xml文件

在工程的源码目录下添加一个名为“applicationContext.xml”的文件,这个文件中可以定义spring的bean文件,内容如下:

  <?xml version="1.0" encoding="UTF-8" ?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

  <bean id=" StudentMgr " class="com.trs.components.mgr.StudentMgr" />

  </beans>

5. 验证Spring是否配置正确

我们定义完spring的配置后,新建一个测试类,只需要按照下面的代码即可获取到“StudentMgr”实例对象,调用代码如下:

// 使用ApplicationContext来初始化系统

ApplicationContext context = new ClassPathXmlApplicationContext(

                "applicationContext.xml");

//通过spring获取实例对象

StudentMgr studentMgr = (StudentMgr) context.getBean("StudentMgr");

System.out.println("-----------");

studentMgr.saveMany("wuguowei");

核心技术:Maven,Springmvc mybatis shiro, Druid, Restful, Dubbo, ZooKeeper,Redis,FastDFS,ActiveMQ,Nginx 
1.     项目核心代码结构截图

利用Maven搭建Spring开发环境 【转】

   项目模块依赖

利用Maven搭建Spring开发环境 【转】

 

特别提醒:开发人员在开发的时候可以将自己的业务REST服务化或者Dubbo服务化

2.    项目依赖介绍

   2.1 后台管理系统、Rest服务系统、Scheculer定时调度系统依赖如下图:

 

利用Maven搭建Spring开发环境 【转】

       2.2 Dubbo独立服务项目依赖如下图:

 利用Maven搭建Spring开发环境 【转】

3.  项目功能部分截图:

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】
 

zookeeper、dubbo服务启动 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】
 

dubbo管控台 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 REST服务平台

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

 

利用Maven搭建Spring开发环境 【转】

转载于:https://my.oschina.net/grthrj/blog/748202

相关文章:

  • 2021-11-17
  • 2021-07-30
  • 2022-12-23
  • 2021-04-30
  • 2021-07-06
  • 2021-08-17
  • 2021-10-13
  • 2021-09-16
猜你喜欢
  • 2022-02-07
  • 2022-02-07
  • 2021-07-05
  • 2021-08-20
  • 2021-09-27
  • 2021-12-23
相关资源
相似解决方案