Commit 7ea17a6d by chengweijun

Springboot和cloud2.x的脚手架

parents
# Default ignored files
/workspace.xml
\ No newline at end of file
basespringcloud2.x
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="demoService" />
<module name="baseService" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="demoervice" target="1.8" />
<module name="demoService" target="1.8" />
<module name="service2" target="1.8" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="baseService" options="-parameters" />
<module name="baseService2" options="-parameters" />
<module name="demoService" options="-parameters" />
<module name="demoervice" options="-parameters" />
<module name="service2" options="-parameters" />
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/baseService/src/main/java" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="date" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/demoService/pom.xml" />
<option value="$PROJECT_DIR$/service2/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
## 介绍
basespringcloud2.x项目 是 基于SpringCloud和SpringBoot2.x版本的一个项目脚手架,完成了基本的工作:
- 基础Maven依赖
- Mybatis代码生成器
- 一些最基础的配置
## Start
利用此项目快速搭建SpringCloud应用,只需要基于baseService创建其他微服务即可
如果我现在想要增加一个demoSerive微服务,那么我需要:
1. 复制baseService文件夹粘贴到项目根目录
![](https://chengweijun.oss-cn-hangzhou.aliyuncs.com/img/复制baseService.png)
2. 将此目录接入项目
先修改此目录下的pom.xml的模块标识符
![](https://chengweijun.oss-cn-hangzhou.aliyuncs.com/img/修改pom标识.png)
在整个项目的pom.xml中添加此子模块
![](https://chengweijun.oss-cn-hangzhou.aliyuncs.com/img/根项目下添加module.png)
3. 修改配置
修改bootstrap-dev.yml 的配置(需要配置使用#config needed注明的项)
![](https://chengweijun.oss-cn-hangzhou.aliyuncs.com/img/修改bootstrap配置.png)
nacos上创建配置文件
```yml
server:
port: 7841 # config needed
spring:
datasource:
username: root # config needed
password: 123456 # config needed
url: jdbc:mysql://IP:3306/springcloudtest?useUnicode=true&characterEncoding=utf8 # config needed
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
max-active: 100
min-idle: 5
max-wait: 60000
pool-prepared-statements: false
max-open-prepared-statements: 20
validation-query: SELECT 1
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
use-global-data-source-stat: true
# filters: stat,wall,log4j
filter:
stat:
enabled: true
db-type: mysql
merge-sql: true
log-slow-sql: true
slow-sql-millis: 1000
connection-init-sqls: SET NAMES utf8mb4
```
修改并启动MybatisPlusGenerator(需要配置Main函数里的几个数据库变量)
![](https://chengweijun.oss-cn-hangzhou.aliyuncs.com/img/修改代码生成器.png)
4. 启动服务,结束
<?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>basespringcloud2.x</artifactId>
<groupId>com.senthink.www</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>baseService</artifactId>
</project>
\ No newline at end of file
package com.senthink.www;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@MapperScan("com.senthink.www.dao")
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class BaseServiceApplication extends SpringBootServletInitializer implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public static void main(String[] args) {
SpringApplication.run(BaseServiceApplication.class,args);
}
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
applicationContext = context;
}
public static Object getBean(String name) {
return applicationContext.getBean(name);
}
public static <T> T getBean(Class<T> requiredType) {
return applicationContext.getBean(requiredType);
}
public static <T> T getBean(String name, Class<T> requiredType) {
return applicationContext.getBean(name, requiredType);
}
}
package com.senthink.www;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import java.util.*;
/**
*
* @author chengwj
* @date 2020/4/17
* @version 1.0
**/
public class MybatisPlusGenerator {
//region 需要配置的项:数据库url、用户名、密码、表名集合(要生成哪些表的代码)
private static String DATA_URL;
private static String DATA_NAME;
private static String DATA_PWD;
private static String[] TABLE_NAMES;
//endregion
//region 无需配置(可采取默认配置)的项:包名、路径
private static final String MAPPER_PACKAGE = "dao";
private static final String SERVICE_PACKAGE = "service";
private static final String SERVICE_IMPL_PACKAGE = "service.impl";
private static final String POJO_PACKAGE = "entity";
private static final String CONTROLLER_PACKAGE = "web";
private static final String MAPPER_XML_PACKAGE = "mapper";
private static final String AUTHOR = "MybatisPlusGenerator";
private static final String PARENT_PACKAGE = MybatisPlusGenerator.class.getPackage().getName();
private static final String MODULE_PATH;
private static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
static {
String path = MybatisPlusGenerator.class.getResource("").getPath();
MODULE_PATH = path.substring(0,path.indexOf("target"));
}
private static final String OUT_PUT_DIR = MODULE_PATH +"src/main/java";
private static final String XML_OUT_PUT_DIR = MODULE_PATH+"src/main/resources/mapper/";
//endregion
public static void main(String[] args) {
DATA_URL = "jdbc:mysql://106.15.251.107:3306/springcloudtest?useUnicode=true&characterEncoding=utf8";
DATA_NAME = "root";
DATA_PWD = "Chengw315";
TABLE_NAMES = new String[]{"service1"};
// 代码生成器
new AutoGenerator()
// 全局配置
.setGlobalConfig(getGlobalConfig())
// 数据源配置
.setDataSource(getDataSourceConfig())
// 包配置
.setPackageInfo(getPackageConfig())
.setCfg(getInjectionConfig())
// 策略配置
.setStrategy(getStrategyConfig())
//生成代码
.execute();
}
/**
* @return 全局配置:生成代码的路径等
*/
public static GlobalConfig getGlobalConfig() {
return new GlobalConfig()
.setOutputDir(OUT_PUT_DIR)
.setDateType(DateType.ONLY_DATE)
.setAuthor(AUTHOR)
.setOpen(false)
.setBaseResultMap(true)
.setBaseColumnList(true)
// 覆盖生成的文件
.setFileOverride(true)
.setServiceName("%sService");
}
/**
* @return 数据源配置
*/
public static DataSourceConfig getDataSourceConfig() {
return new DataSourceConfig()
.setUrl(DATA_URL)
.setDriverName(DRIVER_NAME)
.setUsername(DATA_NAME)
.setPassword(DATA_PWD);
}
/**
* @return 包配置:控制生成代码所在的包
*/
public static PackageConfig getPackageConfig() {
return new PackageConfig()
.setParent(PARENT_PACKAGE)
.setMapper(MAPPER_PACKAGE)
.setEntity(POJO_PACKAGE)
.setService(SERVICE_PACKAGE)
.setController(CONTROLLER_PACKAGE)
.setServiceImpl(SERVICE_IMPL_PACKAGE)
.setXml(MAPPER_XML_PACKAGE);
}
/**
* @return 策略配置
*/
public static StrategyConfig getStrategyConfig() {
return new StrategyConfig()
.setNaming(NamingStrategy.underline_to_camel)
.setColumnNaming(NamingStrategy.underline_to_camel)
.setEntityTableFieldAnnotationEnable(true)
.setEntityLombokModel(true)
.setInclude(TABLE_NAMES)
//默认生成全部
//.setExclude(null)
.setTablePrefix("表前缀_")
.setControllerMappingHyphenStyle(true);
}
/**
* @return 额外的自定义配置:配置了生成XML的路径
*/
public static InjectionConfig getInjectionConfig() {
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
}
};
String templatePath = "/templates/mapper.xml.vm";
// 自定义mapper.XML文件输出配置
List<FileOutConfig> configs = new ArrayList<>();
configs.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return XML_OUT_PUT_DIR + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(configs);
return cfg;
}
}
package com.senthink.www.config.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
/**
* Created by Jason on 2016/11/7.
*/
@Aspect
@Order(5)
@Component
public class WebLogAspect {
private Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
ThreadLocal<Long> startTime = new ThreadLocal<>();
@Pointcut("execution(public * com.senthink.www.web..*.*(..))")
public void webLog() {
}
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
startTime.set(System.currentTimeMillis());
// 接收到请求,记录请求内容
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String ip = "";
if (request.getHeader("x-forwarded-for") == null) {
ip = request.getRemoteAddr();
} else {
ip = request.getHeader("x-forwarded-for").split(",")[0];
}
// 记录下请求内容
logger.info("URL : " + request.getRequestURL().toString());
logger.info("HTTP_METHOD : " + request.getMethod());
logger.info("IP : " + ip);
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
@AfterReturning(returning = "ret", pointcut = "webLog()")
public void doAfterReturning(Object ret) throws Throwable {
// 处理完请求,返回内容
logger.info("RESPONSE : " + ret);
logger.info("SPEND TIME : " + (System.currentTimeMillis() - startTime.get()));
startTime.remove();
}
}
package com.senthink.www.message4Return;
/**
* 数据返回对象
* @author chengwj
* @date 2020/4/17
* @version 1.0
**/
public class Message {
private String code;
private String msg;
private Object data;
private Message() {
}
public Message(MessageType messageType,Object data) {
this.code = messageType.getCode();
this.msg = messageType.getMsg();
this.data = data;
}
public static final Message SUCCESS = new Message(MessageType.SUCCESS,null);
public static final Message ERROR = new Message(MessageType.ERROR, null);
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
public Object getData() {
return data;
}
}
package com.senthink.www.message4Return;
import com.senthink.www.BaseServiceApplication;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
/**
* 数据返回对象的类型。如果想要增加类型,需要通过添加静态MessageType对象实现
* @author chengwj
* @date 2020/4/17
* @version 1.0
**/
public class MessageType {
//国际化
private static MessageSource messageSource = BaseServiceApplication.getBean(MessageSource.class);
private String code;
private String msg;
private String msg_English;
private MessageType() {}
protected MessageType(String code, String msg, String msg_English) {
this.code = code;
this.msg = msg;
this.msg_English = msg_English;
}
public static final MessageType SUCCESS = new MessageType("8001","操作成功","MSG_SUCCESS");
public static final MessageType ERROR = new MessageType("4001","操作失败","MSG_ERROR");
public String getCode() {
return code;
}
public String getMsg() {
return messageSource.getMessage(msg_English,null,msg, LocaleContextHolder.getLocale());
}
}
//package com.senthink.www.service.remote;
//
//import org.springframework.cloud.openfeign.FeignClient;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//
//@Component
//@FeignClient("demoService")
//public interface RemoteDemoService {
//
// @RequestMapping(value = "/demo",method = RequestMethod.GET)
// String demo();
//}
package com.senthink.www.web;
import com.senthink.www.message4Return.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author MybatisPlusGenerator
* @since 2020-04-17
*/
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("/testConnection")
public Message service1List() {
return Message.SUCCESS;
}
}
${AnsiColor.GREEN}
____ _ _ _ _
/ ____| | | | | (_) | |
| (___ ___ _ __ | |_ | |__ _ _ __ | | __
\___ \ / _ \| _ \ | __|| _ \ | || _ \ | |/ /
____) || __/| | | || |_ | | | || || | | || <
|_____/ \___||_| |_| \__||_| |_||_||_| |_||_|\_\
XXX服务 @ Senthink
Spring Boot Version: ${spring-boot.version}
spring:
application:
name: baseService #config needed
cloud:
nacos:
config:
server-addr: ${NACOS_ADDR:106.15.251.107} #config needed
file-extension: yml
namespace: ${NACOS_NAMESPACE:a3773d97-cd74-4c09-b101-238c084f9c7f} #config needed
group: ${NACOS_GROUP:base} #config needed
discovery:
server-addr: ${spring.cloud.nacos.config.server-addr}
service: ${spring.application.name}
namespace: ${spring.cloud.nacos.config.namespace}
ip: ${SERVICE_IP:127.0.0.1} #config needed
${AnsiColor.GREEN}
____ _ _ _ _
/ ____| | | | | (_) | |
| (___ ___ _ __ | |_ | |__ _ _ __ | | __
\___ \ / _ \| _ \ | __|| _ \ | || _ \ | |/ /
____) || __/| | | || |_ | | | || || | | || <
|_____/ \___||_| |_| \__||_| |_||_||_| |_||_|\_\
XXX服务 @ Senthink
Spring Boot Version: ${spring-boot.version}
spring:
application:
name: baseService #config needed
cloud:
nacos:
config:
server-addr: ${NACOS_ADDR:106.15.251.107} #config needed
file-extension: yml
namespace: ${NACOS_NAMESPACE:a3773d97-cd74-4c09-b101-238c084f9c7f} #config needed
group: ${NACOS_GROUP:base} #config needed
discovery:
server-addr: ${spring.cloud.nacos.config.server-addr}
service: ${spring.application.name}
namespace: ${spring.cloud.nacos.config.namespace}
ip: ${SERVICE_IP:127.0.0.1} #config needed
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
<?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>
<modules>
<module>baseService</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.senthink.www</groupId>
<artifactId>basespringcloud2.x</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<!--swagger-ui-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--SpringMVC-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--Mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<!--Mybatis-plus-generator-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1</version>
</dependency>
<!--This is a Mapper.XML-Template-Engine For Mybatis-plus-generator-->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
</dependency>
<!--lombok, just because the codes that Mybatis-Plus generates need this-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<!--Druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.21</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<!--JDBC-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<!--Nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<!--Feign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<!--Ribbon-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment