使用idea maven开发spring boot 分布式开发入门

1:使用idea创建一个maven工程 bos2

2:删除bos2的src 文件夹,向pom.xml文件 中添加版本号

<packaging>pom</packaging>
<?xml version="1.0" encoding="UTF-8"?>
<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>com.li</groupId>
    <artifactId>bos2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>crm_domain</module>
        <module>crm_management</module>
    </modules>
    <packaging>pom</packaging>
    <name>bos2.0</name>
    <description>bos v2.0综合平台</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>

        <spring-data-jpa.version>1.9.0.RELEASE</spring-data-jpa.version>
        <elasticsearch.version>2.4.6</elasticsearch.version>
        <jackson.version>2.8.5</jackson.version>
        <boot-starter-jaxrs.version>3.2.0</boot-starter-jaxrs.version>
        <jna.version>3.0.9</jna.version>
        <ojdbc6.version>11.2.0.1.0</ojdbc6.version>
        <shiro.version>1.4.0</shiro.version>
        <pinyin4j.version>2.5.0</pinyin4j.version>
        <poi.version>3.11</poi.version>
        <httpclient.version>4.5.3</httpclient.version>
        <fastjson.version>1.2.8</fastjson.version>
        <mail.version>1.4.7</mail.version>
        <commons-lang.version>2.6</commons-lang.version>
        <commons-io.version>1.3.2</commons-io.version>
        <itext.version>5.2.0</itext.version>
        <quartz.version>2.2.1</quartz.version>
        <mysql.version>5.1.35</mysql.version>
    </properties>

</project>

2:根目录右键 添加模块,选择maven工程。创建maven子模块 crm_domain

子模块pom.xml添加

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>bos2</artifactId>
        <groupId>com.li</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>crm_domain</artifactId>
    <name>crm_domain</name>
    <description>客户关系系统实体类</description>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

</project>

3:创建对象

package top.kylewang.crm.domain;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;

/**
 * @description:客户信息表
 *
 */
@Entity
@Table(name = "T_CUSTOMER")
@XmlRootElement(name = "customer")
public class Customer {
    @Id
    @GeneratedValue()
    @Column(name = "C_ID")
    private Integer id; // 主键id
    @Column(name = "C_USERNAME")
    private String username; // 用户名
    @Column(name = "C_PASSWORD")
    private String password; // 密码
    @Column(name = "C_TYPE")
    private Integer type; // 类型 设置1 绑定邮箱
    @Column(name = "C_BRITHDAY")
    @Temporal(TemporalType.DATE)
    private Date birthday; // 生日
    @Column(name = "C_SEX")
    private Integer sex; // 性别 1男 2女
    @Column(name = "C_TELEPHONE")
    private String telephone; // 手机
    @Column(name = "C_COMPANY")
    private String company; // 公司
    @Column(name = "C_DEPARTMENT")
    private String department; // 部门
    @Column(name = "C_POSITION")
    private String position; // 职位
    @Column(name = "C_ADDRESS")
    private String address; // 地址
    @Column(name = "C_MOBILEPHONE")
    private String mobilePhone; // 座机
    @Column(name = "C_EMAIL")
    private String email; // 邮箱
    @Column(name = "C_Fixed_AREA_ID")
    private String fixedAreaId; // 定区编码

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFixedAreaId() {
        return fixedAreaId;
    }

    public void setFixedAreaId(String fixedAreaId) {
        this.fixedAreaId = fixedAreaId;
    }

    @Override
    public String toString() {
        return "Customer [id=" + id + ", username=" + username + ", password=" + password + ", type=" + type
                + ", birthday=" + birthday + ", sex=" + sex + ", telephone=" + telephone + ", company=" + company
                + ", department=" + department + ", position=" + position + ", address=" + address + ", mobilePhone="
                + mobilePhone + ", email=" + email + ", fixedAreaId=" + fixedAreaId + "]";
    }

}

3:右键根工程创建一个子模块crm_management,使其依赖 crm_domain.向pom.xml中添加

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>bos2</artifactId>
        <groupId>com.li</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>crm_management</artifactId>
    <packaging>jar</packaging>
    <name>crm_management</name>
    <description>客户关系管理系统</description>

    <dependencies>
        <dependency>
            <groupId>com.li</groupId>
            <artifactId>crm_domain</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
            <version>${boot-starter-jaxrs.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--jaxrs转json工具-->
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <!--commons工具包-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>${commons-lang.version}</version>
        </dependency>

        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

5:在resources目录下添加application.yml,对子模块进行配置

server:
  port: 9002   #配置设置服务的端口号
  context-path: /crm   #路径
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/crm
    username: root
    password: 136735
  jpa:
    show-sql: true   #jpa
  jackson:
    default-property-inclusion: non_null
  devtools:
    restart:
      enabled: true
cxf:
  path: /services
  servlet.init:
    service-list-path: /info
  jaxrs:
    component-scan: true

6:创建controller和applicationMain主函数等

package top.kylewang.crm;

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * @author Kyle.Wang
 * 2018/1/15 0015 11:59
 */

@SpringBootApplication
public class CrmManagementApplication {

    public static void main(String[] args) {
        SpringApplication.run(CrmManagementApplication.class, args);
    }

    @Bean
    public JacksonJaxbJsonProvider jacksonJaxbJsonProvider() {
        return new JacksonJaxbJsonProvider();
    }
}
package top.kylewang.crm.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Test {
    @RequestMapping("hello")
    @ResponseBody
    public String getString(){
        return"hello";
    }
}

7:运行springboot主函数,  访问  http://localhost:9002/crm/hello

结果为hello.

系统结构图

原文地址:https://www.cnblogs.com/liyafei/p/8482843.html

时间: 2024-10-29 02:33:10

使用idea maven开发spring boot 分布式开发入门的相关文章

Spring Boot框架开发的Java项目在CentOS7上的部署

需求:上级拿来一份Spring Boot框架开发的Java项目代码让我在服务器上运行起来,只说了一句该框架是自带了Tomcat(不用重新安装Tomcat),一份代码下有两个项目(一个管理端项目,一个用户端项目,等会会细说).我是一名运维,在上家公司只接触过在Tomcat下部署Java项目,自带Tomcat的没接触过,目前这个公司都是php软件攻城狮,所以只能靠自己了.幸好在一个学习交流群里碰到一位Java软件攻城狮,在该攻城狮的热心指导下项目成功运行.下面是详细步骤,知识点扩展及总结将在最后写出

Springboot 系列(五)Spring Boot web 开发之静态资源和模版引擎

前言 Spring Boot 天生的适合 web 应用开发,它可以快速的嵌入 Tomcat, Jetty 或 Netty 用于包含一个 HTTP 服务器.且开发十分简单,只需要引入 web 开发所需的包,然后编写业务代码即可. 自动配置原理? 在进行 web 开发之前让我再来回顾一下自动配置,可以参考系列文章第三篇.Spring Boot 为 Spring MVC 提供了自动配置,添加了如下的功能: 视图解析的支持. 静态资源映射,WebJars 的支持. 转换器 Converter 的支持.

Spring Boot 2.x 入门前的准备-IntelliJ IDEA 开发工具的安装与使用

常用的用于开发 spring boot 项目的开发工具有 eclipse 和 IntelliJ IDEA 两种,最近有声音提出 visual code 也开始流行开发 java,而且确实如此, vs code 是一个很有潜力的开发工具. 本章,主要讲述在 window 和 mac 操作系统环境下如何安装 IntelliJ IDEA .注意 IntelliJ IDEA 是收费的,也有用于免费的版本供大家开发学习. 在安装 IntelliJ IDEA 之前,你应该知晓如何安装 Java JDK Sp

Spring Boot让开发如此简单

从html到asp后一直专注.net开发,从.net诞生到如今,从winform到webform,从asp.net到.net mcv,从.net mvc到.net core,从ado.net到linq到ef,从ef到.net core ef,之前一直比较忙没什么时间修下java web,虽然对java语言的底层开发早已经熟练(就像精通c#去干安卓的as开发一样得心应手),最近在修下java web开发,发现Spring Boot让开发变得如此简单,但是一直在宇宙第一ide vs的开发环境下,换下

Springboot 系列(六)Spring Boot web 开发之拦截器和三大组件

1. 拦截器 Springboot 中的 Interceptor 拦截器也就是 mvc 中的拦截器,只是省去了 xml 配置部分.并没有本质的不同,都是通过实现 HandlerInterceptor 中几个方法实现.几个方法的作用一一如下. preHandle 进入 Habdler 方法之前执行,一般用于身份认证授权等. postHandle 进入 Handler 方法之后返回 modelAndView 之前执行,一般用于塞入公共模型数据等. afterCompletion 最后处理,一般用于日

在eclipse中安装maven和spring boot

在eclipse中安装maven和spring boot 1.打开help->install new software 2.点Add,Name(maven),Location(http://download.eclipse.org/technology/m2e/releases),OK,select然后next到安装中,等待安装完成. 3.新建maven项目 File->New->Project, 选择Maven Project next到 输入artifact id(项目名).grou

Maven 搭建spring boot多模块项目

Maven 搭建spring boot多模块项目 备注:所有项目都在idea中创建 1.idea创建maven项目 1-1: 删除src,target目录,只保留pom.xml 1-2: 根目录pom.xml可被子模块继承,因此项目只是demo,未考虑太多性能问题,所以将诸多依赖 都写在根级`pom.xml`,子模块只需继承就可以使用. 1-3: 根级pom.xml文件在附录1 1-4: 依赖模块 mybatis spring-boot相关模块 2.创建子模块(module) 2-1: file

spring boot分布式技术,spring cloud,负载均衡,配置管理器

spring boot分布式的实现,使用spring cloud技术. 下边是我理解的spring cloud的核心技术: 1.配置服务器 2.注册发现服务器eureka(spring boot默认使用的服务器类别) 3.RestTemplate通过ribbon实现负载均衡技术 具体请看下列图: 参考:http://www.cnblogs.com/skyblog/p/5127690.html

Spring Boot【快速入门】

Spring Boot 概述 Build Anything with Spring Boot:Spring Boot is the starting point for building all Spring-based applications. Spring Boot is designed to get you up and running as quickly as possible, with minimal upfront configuration of Spring. 上面是引自