Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloudAlibaba
提交
210111cd
S
SpringCloudAlibaba
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringCloudAlibaba
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringCloudAlibaba
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
210111cd
编写于
2月 12, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:新增服务实例
上级
7d7e0a7f
变更
29
显示空白变更内容
内联
并排
Showing
29 changed file
with
479 addition
and
8 deletion
+479
-8
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/NacosConsumerApplication.java
...com/kwan/springcloudalibaba/NacosConsumerApplication.java
+9
-1
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
...springcloudalibaba/controller/ConsumerUserController.java
+17
-0
nacos-server-producer-9091/pom.xml
nacos-server-producer-9091/pom.xml
+3
-3
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/NacosProducer9091Application.java
...kwan/springcloudalibaba/NacosProducer9091Application.java
+3
-3
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
...com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
+0
-0
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
...pringcloudalibaba/controller/NacosProducerController.java
+0
-0
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
...om/kwan/springcloudalibaba/controller/UserController.java
+0
-0
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/entity/User.java
...rc/main/java/com/kwan/springcloudalibaba/entity/User.java
+0
-0
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
...n/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
+0
-0
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
...ava/com/kwan/springcloudalibaba/service/IUserService.java
+0
-0
nacos-server-producer-9091/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
...kwan/springcloudalibaba/service/impl/UserServiceImpl.java
+0
-0
nacos-server-producer-9091/src/main/resources/bootstrap.yml
nacos-server-producer-9091/src/main/resources/bootstrap.yml
+0
-0
nacos-server-producer-9091/src/main/resources/logback-spring.xml
...erver-producer-9091/src/main/resources/logback-spring.xml
+0
-0
nacos-server-producer-9091/src/main/resources/mapper/UserMapper.xml
...er-producer-9091/src/main/resources/mapper/UserMapper.xml
+0
-0
nacos-server-producer-9091/src/test/java/com/kwan/springcloudalibaba/NacosApplicationTests.java
...va/com/kwan/springcloudalibaba/NacosApplicationTests.java
+0
-0
nacos-server-producer-9092/pom.xml
nacos-server-producer-9092/pom.xml
+89
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/NacosProducer9092Application.java
...kwan/springcloudalibaba/NacosProducer9092Application.java
+22
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
...com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
+31
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
...pringcloudalibaba/controller/NacosProducerController.java
+26
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
...om/kwan/springcloudalibaba/controller/UserController.java
+53
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/entity/User.java
...rc/main/java/com/kwan/springcloudalibaba/entity/User.java
+24
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
...n/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
+20
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
...ava/com/kwan/springcloudalibaba/service/IUserService.java
+32
-0
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
...kwan/springcloudalibaba/service/impl/UserServiceImpl.java
+37
-0
nacos-server-producer-9092/src/main/resources/bootstrap.yml
nacos-server-producer-9092/src/main/resources/bootstrap.yml
+20
-0
nacos-server-producer-9092/src/main/resources/logback-spring.xml
...erver-producer-9092/src/main/resources/logback-spring.xml
+69
-0
nacos-server-producer-9092/src/main/resources/mapper/UserMapper.xml
...er-producer-9092/src/main/resources/mapper/UserMapper.xml
+9
-0
nacos-server-producer-9092/src/test/java/com/kwan/springcloudalibaba/NacosApplicationTests.java
...va/com/kwan/springcloudalibaba/NacosApplicationTests.java
+13
-0
pom.xml
pom.xml
+2
-1
未找到文件。
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/NacosConsumerApplication.java
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba
;
import
com.netflix.loadbalancer.IRule
;
import
com.netflix.loadbalancer.RandomRule
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -22,7 +24,13 @@ public class NacosConsumerApplication {
return
new
RestTemplate
();
}
@Bean
public
IRule
randomRule
()
{
return
new
RandomRule
();
//随机
//return new RoundRobinRule(); //轮训
//return new BestAvailableRule();
//return new ZoneAvoidanceRule(); //新版本默认的策略
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
NacosConsumerApplication
.
class
,
args
);
}
...
...
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
浏览文件 @
210111cd
...
...
@@ -50,6 +50,7 @@ public class ConsumerUserController {
return
Result
.
ok
(
restTemplate
.
getForObject
(
url
,
Result
.
class
));
}
/**
* 使用ip访问
* http://127.0.0.1:8085/nacos/consumer/loadBalancerClientIp/1
...
...
@@ -67,6 +68,22 @@ public class ConsumerUserController {
return
Result
.
ok
(
restTemplate
.
getForObject
(
url
,
Result
.
class
));
}
/**
* 通过服务名进行负载均衡访问
* http://127.0.0.1:8085/nacos/consumer/serverName/1
*
* @param id
* @return
*/
@GetMapping
(
value
=
"/serverName/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
serverName
(
@PathVariable
(
"id"
)
Integer
id
)
{
String
url
=
"http://nacos-server-producer/user/"
+
id
;
System
.
out
.
println
(
"request url:"
+
url
);
return
Result
.
ok
(
restTemplate
.
getForObject
(
url
,
Result
.
class
));
}
/**
* feign调用
* http://127.0.0.1:8085/nacos/consumer/1
...
...
nacos-server-producer/pom.xml
→
nacos-server-producer
-9091
/pom.xml
浏览文件 @
210111cd
...
...
@@ -19,9 +19,9 @@
<artifactId>
nacos-server-parent
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</parent>
<artifactId>
nacos-server-producer
</artifactId>
<name>
nacos-server-producer
</name>
<description>
nacos-server-producer
</description>
<artifactId>
nacos-server-producer
-9091
</artifactId>
<name>
nacos-server-producer
-9091
</name>
<description>
nacos-server-producer
-9091
</description>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
...
...
nacos-server-producer
/src/main/java/com/kwan/springcloudalibaba/NacosProducer
Application.java
→
nacos-server-producer
-9091/src/main/java/com/kwan/springcloudalibaba/NacosProducer9091
Application.java
浏览文件 @
210111cd
...
...
@@ -13,10 +13,10 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
* @date : 2023/1/17 12:37
*/
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
public
class
NacosProducerApplication
{
public
class
NacosProducer
9091
Application
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
NacosProducerApplication
.
class
,
args
);
System
.
out
.
println
(
"-----------------------nacos-server-producer启动成功-----------------------"
);
SpringApplication
.
run
(
NacosProducer
9091
Application
.
class
,
args
);
System
.
out
.
println
(
"-----------------------nacos-server-producer
-9091
启动成功-----------------------"
);
}
}
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/entity/User.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/entity/User.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
→
nacos-server-producer
-9091
/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/resources/bootstrap.yml
→
nacos-server-producer
-9091
/src/main/resources/bootstrap.yml
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/resources/logback-spring.xml
→
nacos-server-producer
-9091
/src/main/resources/logback-spring.xml
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/main/resources/mapper/UserMapper.xml
→
nacos-server-producer
-9091
/src/main/resources/mapper/UserMapper.xml
浏览文件 @
210111cd
文件已移动
nacos-server-producer/src/test/java/com/kwan/springcloudalibaba/NacosApplicationTests.java
→
nacos-server-producer
-9091
/src/test/java/com/kwan/springcloudalibaba/NacosApplicationTests.java
浏览文件 @
210111cd
文件已移动
nacos-server-producer-9092/pom.xml
0 → 100644
浏览文件 @
210111cd
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
8
</source>
<target>
8
</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>
com.kwan.springcloudalibaba
</groupId>
<artifactId>
nacos-server-parent
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</parent>
<artifactId>
nacos-server-producer-9092
</artifactId>
<name>
nacos-server-producer-9092
</name>
<description>
nacos-server-producer-9092
</description>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<spring-boot.version>
2.3.7.RELEASE
</spring-boot.version>
<spring-cloud-alibaba.version>
2.2.2.RELEASE
</spring-cloud-alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloudalibaba
</groupId>
<artifactId>
nacos-server-common
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-config
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
3.4.3
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.2.3
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.9
</version>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.11
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/NacosProducer9092Application.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
/**
* http://localhost:18082/nacos/nameInfo
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/17 12:37
*/
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
public
class
NacosProducer9092Application
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
NacosProducer9092Application
.
class
,
args
);
System
.
out
.
println
(
"-----------------------nacos-server-producer-9092启动成功-----------------------"
);
}
}
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.config
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* mybatisplus配置
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:11
*/
@MapperScan
(
"com.kwan.springcloudalibaba.mapper"
)
//扫描我们的mapper文件夹 这里添加了@MapperScan注解就不需要Springboot启动类上加入@MapperScan注解了
@Configuration
//配置类
public
class
MyBatisPlusConfig
{
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
()
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
//注册乐观锁插件
interceptor
.
addInnerInterceptor
(
new
OptimisticLockerInnerInterceptor
());
//分页插件
interceptor
.
addInnerInterceptor
(
new
PaginationInnerInterceptor
(
DbType
.
MYSQL
));
return
interceptor
;
}
}
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.controller
;
import
com.kwan.springcloudalibaba.common.Result
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RefreshScope
@RestController
@RequestMapping
(
"/nacos/producer"
)
public
class
NacosProducerController
{
/**
* 获取配置的变量
*/
@GetMapping
(
value
=
"/nameInfo"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
nameInfo
()
{
return
Result
.
ok
();
}
}
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.controller
;
import
com.kwan.springcloudalibaba.common.Result
;
import
com.kwan.springcloudalibaba.entity.User
;
import
com.kwan.springcloudalibaba.service.IUserService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* 用户相关
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:08
*/
@Slf4j
@RestController
@RequestMapping
(
"/user"
)
public
class
UserController
{
@Autowired
private
IUserService
userService
;
/**
* 通过主键查询单条数据
*
* http://localhost:9091/user/1
*
* @param id 主键
* @return 单条数据
*/
@GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
selectOne
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
userService
.
getUserById
(
id
));
}
@RequestMapping
(
value
=
"/all"
,
method
=
RequestMethod
.
GET
)
public
List
<
User
>
addAdvertise
()
{
log
.
info
(
"测试日志={}"
,
"success"
);
return
userService
.
getUsers
();
}
@RequestMapping
(
value
=
"/getUserByName"
,
method
=
RequestMethod
.
GET
)
public
User
getUserByName
(
@RequestParam
String
sex
)
{
return
userService
.
getUserByName
(
sex
);
}
}
\ No newline at end of file
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/entity/User.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@Builder
@TableName
(
value
=
"user"
)
@AllArgsConstructor
@NoArgsConstructor
public
class
User
{
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
String
name
;
private
String
sex
;
}
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.kwan.springcloudalibaba.entity.User
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* mapper文件
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:12
*/
@Mapper
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
User
getUserByName
(
String
sex
);
}
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.kwan.springcloudalibaba.entity.User
;
import
java.util.List
;
public
interface
IUserService
extends
IService
<
User
>
{
/**
* 获取所有用户
*
* @return
*/
List
<
User
>
getUsers
();
/**
* 获取一个用户
*
* @return
*/
User
getUserById
(
Integer
id
);
/**
* 根据姓名查询
*
* @param sex
* @return
*/
User
getUserByName
(
String
sex
);
}
nacos-server-producer-9092/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.kwan.springcloudalibaba.entity.User
;
import
com.kwan.springcloudalibaba.mapper.UserMapper
;
import
com.kwan.springcloudalibaba.service.IUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Objects
;
@Service
public
class
UserServiceImpl
extends
ServiceImpl
<
UserMapper
,
User
>
implements
IUserService
{
@Autowired
private
UserMapper
userMapper
;
@Override
public
List
<
User
>
getUsers
()
{
return
userMapper
.
selectList
(
null
);
}
@Override
public
User
getUserById
(
Integer
id
)
{
return
userMapper
.
selectById
(
id
);
}
@Override
public
User
getUserByName
(
String
sex
)
{
User
userByName
=
userMapper
.
getUserByName
(
sex
);
if
(
Objects
.
isNull
(
userByName
))
{
userByName
=
new
User
();
}
return
userByName
;
}
}
\ No newline at end of file
nacos-server-producer-9092/src/main/resources/bootstrap.yml
0 → 100644
浏览文件 @
210111cd
#端口号
server
:
port
:
9092
#spring配置
spring
:
application
:
name
:
nacos-server-producer
profiles
:
active
:
dev
cloud
:
nacos
:
discovery
:
server-addr
:
http://120.79.36.53:8848
#服务注册地址
config
:
server-addr
:
http://120.79.36.53:8848
#配置中心地址
file-extension
:
yaml
#文件类型
group
:
DEV_GROUP
#组别
namespace
:
4cd9bd32-8f25-45cd-b919-df1a0df146e0
#命名空间
refresh-enabled
:
true
#默认自动刷新
\ No newline at end of file
nacos-server-producer-9092/src/main/resources/logback-spring.xml
0 → 100644
浏览文件 @
210111cd
<?xml version="1.0" encoding="UTF-8"?>
<configuration
debug=
"true"
>
<!-- 此xml在spring-boot-1.5.3.RELEASE.jar里 -->
<include
resource=
"org/springframework/boot/logging/logback/defaults.xml"
/>
<!--控制台打印日志,不需要配置appender了-->
<include
resource=
"org/springframework/boot/logging/logback/console-appender.xml"
/>
<!-- 开启后可以通过jmx动态控制日志级别(springboot Admin的功能) -->
<!--<jmxConfigurator/>-->
<!--总日志-->
<appender
name=
"ALL-FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--日志存放路径-->
<file>
../logs/springboot-mybatis.log
</file>
<encoder>
<!-- pattern节点,用来设置日志的输入格式 -->
<pattern>
%date [%level] [%thread] %logger{60} [%file : %line] %msg%n
</pattern>
<!--文件编码格式-->
<charset>
UTF-8
</charset>
</encoder>
<!-- 滚动策略 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!-- 添加.gz 历史日志会启用压缩 大大缩小日志文件所占空间 -->
<fileNamePattern>
../logs/springboot-mybatis.log.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 保留30天日志 -->
<maxHistory>
30
</maxHistory>
<!--文件最大存储-->
<totalSizeCap>
10GB
</totalSizeCap>
</rollingPolicy>
</appender>
<!--错误日志-->
<appender
name=
"ERROR-FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--日志存放路径-->
<file>
../logs/error.log
</file>
<encoder>
<pattern>
%date [%level] [%thread] %logger{60} [%file : %line] %msg%n
</pattern>
<!--文件编码格式-->
<charset>
UTF-8
</charset>
</encoder>
<!-- 滚动策略 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!-- 添加.gz 历史日志会启用压缩 大大缩小日志文件所占空间 -->
<fileNamePattern>
../logs/error.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 保留30天日志 -->
<maxHistory>
30
</maxHistory>
<!--文件最大存储-->
<totalSizeCap>
10GB
</totalSizeCap>
</rollingPolicy>
<!-- 过滤日志 -->
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<level>
ERROR
</level>
<!-- 用于配置符合过滤条件的操作 -->
<onMatch>
ACCEPT
</onMatch>
<!-- 用于配置不符合过滤条件的操作 -->
<onMismatch>
DENY
</onMismatch>
</filter>
</appender>
<logger
name=
"com.kwan.springbootkwan"
level=
"INFO"
/>
<root
level=
"INFO"
>
<!--控制台打印日志-->
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"ALL-FILE"
/>
<appender-ref
ref=
"ERROR-FILE"
/>
</root>
</configuration>
\ No newline at end of file
nacos-server-producer-9092/src/main/resources/mapper/UserMapper.xml
0 → 100644
浏览文件 @
210111cd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.kwan.springcloudalibaba.mapper.UserMapper"
>
<select
id=
"getUserByName"
resultType=
"com.kwan.springcloudalibaba.entity.User"
>
SELECT *
FROM user
WHERE sex = #{sex}
</select>
</mapper>
nacos-server-producer-9092/src/test/java/com/kwan/springcloudalibaba/NacosApplicationTests.java
0 → 100644
浏览文件 @
210111cd
package
com.kwan.springcloudalibaba.springcloudalibabaservernacos
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
NacosApplicationTests
{
@Test
void
contextLoads
()
{
}
}
pom.xml
浏览文件 @
210111cd
...
...
@@ -21,7 +21,8 @@
<modules>
<module>
nacos-server-common
</module>
<module>
nacos-server-producer
</module>
<module>
nacos-server-producer-9091
</module>
<module>
nacos-server-producer-9092
</module>
<module>
nacos-server-consumer
</module>
<module>
nacos-feign-api
</module>
<module>
nacos-server-sentinel-consumer
</module>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录