本项目暂定项目名GooReeyProject,SpringBoot + Vue构建,具体项目内容未定。
基本架构nacos、gateway、Linux、Redis、rabbitMQ、MySQL、docker、Vue。
我安装的是window版的nacos和MySQL,安装nacos时需要注意,要讲配置文件中的集群版改为单机版,才能启动!
我觉得主要是pom文件
<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.0modelVersion>
<groupId>com.guorgroupId>
<artifactId>GooReeyProjectartifactId>
<version>1.0-SNAPSHOTversion>
<modules>
<module>01commonmodule>
<module>02gatewaymodule>
modules>
<properties>
<system.version>1.0.0system.version>
<system.ip>127.0.0.1system.ip>
<system.sport>808system.sport>
<system.mode>httpsystem.mode>
<java.version>1.8java.version>
<spring-cloud.version>Greenwich.SR1spring-cloud.version>
<skipTests>trueskipTests>
<nacos.version>0.2.2.RELEASEnacos.version>
properties>
<packaging>pompackaging>
<name>GooReeyProjectname>
<description>This is parent projectdescription>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.1.4.RELEASEversion>
parent>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<scope>providedscope>
dependency>
<dependency>
<groupId>commons-langgroupId>
<artifactId>commons-langartifactId>
<version>2.6version>
dependency>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelper-spring-boot-starterartifactId>
<version>1.2.5version>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>1.1.23version>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
<version>0.2.1.RELEASEversion>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>${spring-cloud.version}version>
<type>pomtype>
<scope>importscope>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-alibaba-dependenciesartifactId>
<version>${nacos.version}version>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<build>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.*include>
includes>
resource>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.ymlinclude>
includes>
<filtering>truefiltering>
resource>
<resource>
<directory>src/main/javadirectory>
<includes>
<include>**/*.xmlinclude>
includes>
resource>
resources>
build>
project>
<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>GooReeyProjectartifactId>
<groupId>com.guorgroupId>
<version>1.0-SNAPSHOTversion>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>02gatewayartifactId>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>2.0.1version>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-gatewayartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-hystrixartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-ribbonartifactId>
exclusion>
exclusions>
dependency>
dependencies>
dependencyManagement>
<build>
<finalName>gateway-${system.version}finalName>
build>
project>
spring:
application:
name: gateway
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
config:
server-addr: 127.0.0.1:8848
file-extension: yml
ext-config:
- data-id: datasource-share-config.yml
group: SHARE_GROUP
refresh: true
- data-id: log-share-config.yml
group: SHARE_GROUP
refresh: true
(1)gateway.yml
server:
port: 8080
spring:
application:
name: gateway
version: 1.0.0
cloud:
gateway:
discovery:
locator:
enabled: true
lowerCaseServiceId: true
filters:
- StripPrefix=1
routes:
- id: management
uri: lb:management # 服务端 service_id
predicates:
- Path=/management/**
filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/defaultFallback
- id: demo
uri: lb://demo
predicates:
- Path=/demo/**
hystrix:
command:
default:
execution:
isolation:
strategy: SEMAPHORE
thread:
timeoutInMilliseconds: 1500
(2)datasource-share-config.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/blue?serverTimezone=UTC
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: root
mybatis:
typeAliasesPackage: com.guor.*.bean.**
mapperLocations: classpath*:**/com/guor/**/dao/mapping/*Mapper.xml
configuration:
map-underscore-to-camel-case: true
(3)log-share-config.yml
logging:
path: logs
level:
root: info
com.alibaba.nacos.client.naming: warn
file:
max-size: 20MB
max-history: 30
pattern:
file: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:%5p} ${PID:- } --- [%15.15t] %-40.40logger{39} [%5.5line] : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}"
console: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} %clr(${LOG_LEVEL_PATTERN:%5p}) %clr(${PID:- }){magenta} --- %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr([%5.5line]){cyan} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}"
package com.guor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDiscoveryClient
@EnableScheduling
@RefreshScope
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
System.out.println("hello world");
}
}
<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>GooReeyProjectartifactId>
<groupId>com.guorgroupId>
<version>1.0-SNAPSHOTversion>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>03managementartifactId>
<properties>
<maven.compiler.source>8maven.compiler.source>
<maven.compiler.target>8maven.compiler.target>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>2.0.1version>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-jdbcartifactId>
dependency>
dependencies>
<build>
<finalName>management-${system.version}finalName>
build>
project>
spring:
application:
name: management
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
config:
server-addr: 127.0.0.1:8848
file-extension: yml
ext-config:
- data-id: datasource-share-config.yml
group: SHARE_GROUP
refresh: true
- data-id: log-share-config.yml
group: SHARE_GROUP
refresh: true
server:
port: 8081
spring:
application:
name: management
version: 1.0.0
mvc:
static-path-pattern: /management/**
resources:
static-locations:
- file:../../web/management
- file:../../web/common
package com.guor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "com.guor")
@MapperScan("com.guor.management.dao")
@RefreshScope
public class ManagementApplication {
public static void main(String[] args) {
SpringApplication.run(ManagementApplication.class, args);
}
}
数据库选择的是最常用的MySQL
CREATE TABLE `user` (
`user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL,
`password` varchar(40) NOT NULL,
`age` int(11) DEFAULT NULL,
`sex` int(11) DEFAULT NULL,
`telephone` varchar(100) DEFAULT NULL,
`address` varchar(100) DEFAULT NULL,
`create_date` date DEFAULT NULL,
`update_date` date DEFAULT NULL,
`deleted` int(11) DEFAULT NULL,
`version` int(11) DEFAULT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
package com.guor.management.controller;
import com.guor.management.bean.User;
import com.guor.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/getUserList")
public List<User> getUserList(){
return userService.getUserList();
}
@PutMapping("/insertUser")
public void insertUser(@RequestBody User user){
userService.insertUser(user);
}
}
package com.guor.management.service;
import com.guor.management.bean.User;
import java.util.List;
public interface UserService {
List<User> getUserList();
void insertUser(User user);
}
package com.guor.management.service.impl;
import com.guor.management.bean.User;
import com.guor.management.dao.UserMapper;
import com.guor.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List<User> getUserList() {
return userMapper.getUserList();
}
@Override
public void insertUser(User user) {
userMapper.insertUser(user);
}
}
package com.guor.management.dao;
import com.guor.management.bean.User;
import java.util.List;
public interface UserMapper {
public List<User> getUserList();
public void insertUser(User user);
}
DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.guor.management.dao.UserMapper">
<select id="getUserList" resultType="java.util.LinkedHashMap">
select * from user;
select>
<insert id="insertUser" parameterType="com.guor.management.bean.User">
INSERT INTO gooreey.`user` (username, password) VALUES (#{username}, #{password});
insert>
mapper>
package com.guor.management.bean;
import com.guor.base.bean.BaseBean;
import lombok.Data;
@Data
public class User extends BaseBean {
private Integer userId;
private String username;
private String password;
private Integer age;
private Integer sex;
private String telephone;
private String address;
}
package com.guor.base.bean;
import lombok.Data;
import java.util.Date;
@Data
public class BaseBean {
private Date createDate;
private Date updateDate;
private Integer deleted;
private Integer version;
}
哪吒精华文章汇总
Java热门专栏
SpringBoot进阶实战