44 Commits

Author SHA1 Message Date
bamanker
8e2281060c 更改构建命令,适应gitea
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2026-01-05 18:08:25 +08:00
bamanker
e2d44f9e89 升级springboot为4.0.1 2026-01-05 17:51:38 +08:00
bamanker
40a3a12233 fix了k8s devops的配置 2023-11-30 23:25:26 +08:00
bamanker
7a145c40bd fix了k8s devops的配置 2023-11-28 00:55:23 +08:00
bamanker
89efefd7c1 fix了k8s devops的配置 2023-11-28 00:39:56 +08:00
bamanker
c3e0a2cf6e 增加了k8s devops的配置 2023-11-23 15:45:57 +08:00
bamanker
b80bdb6370 增加了k8s devops的配置 2023-11-23 15:38:44 +08:00
bamanker
9f35e58970 Merge remote-tracking branch 'origin/version3-native-localBuild' into version3-native-localBuild 2023-11-23 15:23:59 +08:00
bamanker
e0d0e9701b 增加了k8s devops的配置 2023-11-23 15:23:33 +08:00
bamanker
90c2dc3a05 增加了k8s devops的配置 2023-11-23 15:21:39 +08:00
bamanker
d51ffb35c9 增加了k8s devops的配置 2023-11-23 15:08:12 +08:00
bamanker
eaec895ff0 增加了k8s devops的配置 2023-11-23 15:03:54 +08:00
bamanker
4d660bbff8 增加了k8s devops的配置 2023-11-23 14:55:43 +08:00
bamanker
70f55ef987 增加了k8s devops的配置 2023-11-23 14:54:22 +08:00
bamanker
773a759473 增加了k8s devops的配置 2023-11-23 13:46:49 +08:00
bamanker
ed7ce1279a 增加了k8s devops的配置 2023-11-23 12:59:54 +08:00
bamanker
524f0f63ae 增加了k8s devops的配置 2023-11-23 11:47:21 +08:00
bamanker
a6699e26a7 增加了k8s devops的配置 2023-11-23 11:10:07 +08:00
bamanker
b79710a1fc 添加了GraalVM的原生镜像版本-本地编译版本
-修复了@Resource注入失败导致的程序跑不起来的问题
2023-11-13 15:30:11 +08:00
bamanker
af50397afb 添加了GraalVM的原生镜像版本-本地编译版本
-添加了dockerfile中workdir参数2
2023-11-11 21:31:37 +08:00
bamanker
888b0e670f 添加了GraalVM的原生镜像版本-本地编译版本
-添加了dockerfile中workdir参数2
2023-11-11 21:24:20 +08:00
bamanker
6067550bd2 添加了GraalVM的原生镜像版本-本地编译版本
-添加了dockerfile中workdir参数1
2023-11-11 21:04:18 +08:00
bamanker
e0d5d784f8 添加了GraalVM的原生镜像版本-本地编译版本
-添加了dockerfile中workdir参数
2023-11-11 20:49:55 +08:00
bamanker
5ae844ea33 添加了GraalVM的原生镜像版本-本地编译版本
-修复了若干bug(容器中应用无法打开的问题)
2023-11-11 20:33:14 +08:00
bamanker
6eaa123087 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile中的ENTRYPOINT参数
2023-11-11 18:58:57 +08:00
bamanker
f8c2ea8206 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile3
2023-11-11 18:34:16 +08:00
bamanker
cf10cec717 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile3
2023-11-11 18:14:56 +08:00
bamanker
7513fac8d8 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile2
2023-11-11 18:10:40 +08:00
bamanker
f46c78b9f1 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile2
2023-11-11 18:07:03 +08:00
bamanker
659c8e6f3b 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile1
2023-11-11 17:57:32 +08:00
bamanker
3d6530f148 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile1
2023-11-11 17:52:40 +08:00
bamanker
0c00085e9f 添加了GraalVM的原生镜像版本-本地编译版本
修改dockerfile
2023-11-11 17:38:17 +08:00
bamanker
474b16c662 添加了GraalVM的原生镜像版本-本地编译版本
修改了构建器参数,增加了jfr监控等
2023-11-11 17:23:01 +08:00
bamanker
3a18a6b7a6 添加了GraalVM的原生镜像版本-本地编译版本3 2023-11-11 12:18:05 +08:00
bamanker
9cb5e77bb5 添加了GraalVM的原生镜像版本-本地编译版本2 2023-11-11 11:43:06 +08:00
bamanker
392c50ceb9 添加了GraalVM的原生镜像版本-本地编译版本1 2023-11-11 11:34:36 +08:00
bamanker
38152b7786 添加了GraalVM的原生镜像版本-本地编译版本 2023-11-11 11:27:14 +08:00
bamanker
e11418a3fa 添加了GraalVM的原生镜像版本 2023-11-09 23:43:24 +08:00
bamanker
62babb92ac 添加了GraalVM的原生镜像版本 2023-11-09 23:25:46 +08:00
bamanker
27096c2cd2 添加了GraalVM的原生镜像版本 2023-11-09 23:24:47 +08:00
bamanker
fc3ed87fe7 添加了GraalVM的原生镜像版本 2023-11-09 22:56:44 +08:00
bamanker
a58a15c674 优化了构建参数3 2023-06-13 19:54:41 +08:00
bamanker
57785ac9da 优化了构建参数2 2023-06-13 19:45:17 +08:00
bamanker
029d17a66c 优化了构建参数 2023-06-12 13:48:38 +08:00
16 changed files with 663 additions and 192 deletions

3
.dockerignore Normal file
View File

@@ -0,0 +1,3 @@
*
!target/dailylove*
!Dockerfile

170
.gitea/workflows/build.yml Normal file
View File

@@ -0,0 +1,170 @@
name: Build Push and Deploy Image
on:
push:
#tag 触发
tags:
- 'v*'
# 分支触发
# branches:
# - main
workflow_dispatch: #手动构建h
#设置全局环境变量
env:
PATH: /opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAMESPACE: bamanker # todo 可以通过读取pom文件获取下面这些属性值
IMAGE_NAME: dailylove
APP_NAME: daily-love
# 构建 Job
jobs:
build:
runs-on: ubuntu-node22 # 如果host构建:linux_amd64
# container:
# image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/ghcr.io/catthehacker/ubuntu:act-latest
steps:
- name: Print system info 1
run: echo " The job was automatically triggered by a ${{ gitea.event_name }} event."
- name: Print system info 2
run: echo " This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- name: Print system info 3
run: echo " The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Print env
run: env && blkid
- name: Install dependencies
run: |
apt-get update &&
apt-get install -y gettext &&
apt-get install -y maven &&
apt-get install -y sudo &&
apt-get install -y iptables
- name: Set up Docker
uses: http://139.9.216.111:3000/bamanker/setup-docker-action@v4.6.0
with:
# 版本大于28会有兼容性问题
version: type=archive,channel=stable,version=v27.4.0
daemon-config: |
{
"registry-mirrors":["https://docker.1ms.run"],
"dns": ["8.8.8.8", "114.114.114.114"]
}
- name: Generate maven config
uses: http://139.9.216.111:3000/bamanker/maven-settings-action@v3.1.0
with:
mirrors: '[{"id": "alimaven", "name": "aliyun maven", "mirrorOf": "central", "url": "http://maven.aliyun.com/nexus/content/groups/public/"}]'
# - uses: http://localhost:3000/bamanker/setup-node@v6
# with:
# node-version: 24
# cache: 'npm'
# - run: node -v
# 下载仓库源码依赖node环境因此构建服务器本地需要下载安装node并设置环境变量
- name: Checkout repository code
#使用自定义仓库action
uses: http://139.9.216.111:3000/bamanker/checkout@v4
# 获取 TAG 并设置为环境变量
- name: Get version
id: get_version
# e.g. refs/tags/v1.0.0
run: |
echo "APP_TAG=${GITHUB_REF/refs\/tags\/v}" >> $GITHUB_ENV
# 检查 TAG 并传参
- name: Set envVar
id: set_envar
run: |
echo "The app version is $APP_TAG" && echo "tag=$APP_TAG" >> $GITHUB_OUTPUT &&
echo "now workspace: ${{ github.workspace }}"
# 为其他配置文件注入环境变量
- name: Inject envVar
run: |
envsubst < ./deployment-temp.yml > ./deployment.yml &&
cat ./deployment.yml
# 安装java环境
- name: Set up Java
uses: http://139.9.216.111:3000/bamanker/setup-graalvm@v1
with:
distribution: 'graalvm'
java-version: '25.0.1'
cache: 'maven'
# maven 构建
- name: Build with Maven
run: mvn clean native:compile -DskipTests -Pnative
# 登录镜像仓库,方便后续上传镜像
- name: Login to Docker Registry
uses: http://139.9.216.111:3000/bamanker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# # 获取时间戳
# - name: Get datetime
# id: datetime
# run: |
# echo "datetime=$(date '+%Y-%m-%d-%H-%M-%S')" >> $GITHUB_OUTPUT
# 构建并上传镜像
- name: Build and push Docker image
# uses: http://139.9.216.111:3000/bamanker/build-push-action@v4
# 获取上一步截取到的版本号,既 1.0.0
#只能这样接收
env:
TAG: ${{ steps.set_envar.outputs.tag }}
run: |
ls &&
docker build --file Dockerfile --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} . &&
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
# uses: http://139.9.216.111:3000/bamanker/docker-build-push@v5
# with:
# context: .
## platforms: linux/amd64
# file: Dockerfile
# push: true
# tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
#发布到 k8s
#安装 kubectl
- name: Setup kubectl
run: |
curl -LO "https://dl.k8s.io/release/v1.33.0/bin/linux/amd64/kubectl" &&
chmod +x kubectl &&
mv kubectl /usr/local/bin/
- name: Configure kubeconfig
# 假设您的 KUBE_CONFIG 秘密是 Base64 编码的 kubeconfig 文件内容
run: |
# 1. 创建 ~/.kube 目录
mkdir -p $HOME/.kube
# 2. 将 Base64 编码的 KUBE_CONFIG 秘密解码并写入默认配置文件
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > $HOME/.kube/config
# 3. 确保 kubectl 知道配置文件的位置 (可选, 但安全)
echo "KUBECONFIG=$HOME/.kube/config" >> $GITHUB_ENV
- name: Deploy with kubectl
run: |
kubectl apply -f ./deployment.yml
- name: k8s Check Pods Health
run: |
kubectl get pod -n default -l app=${{ env.APP_NAME }}
- name: k8s Update Deployment
run: |
kubectl rollout restart deployment ${{ env.APP_NAME }}

33
.gitignore vendored
View File

@@ -1,33 +0,0 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

View File

@@ -1,7 +1,5 @@
FROM openjdk:8
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/ubuntu:jammy
MAINTAINER bamanker
ADD target/dailyLove-0.1.6.jar /home/dailyLove/
ADD start.sh /home/dailyLove/
RUN chmod +x /home/dailyLove/start.sh
COPY target/dailylove /root/dailylove/
EXPOSE 13145
CMD ["sh","/home/dailyLove/start.sh"]
CMD /root/dailylove/dailylove -XX:StartFlightRecording='filename=recording.jfr,dumponexit=true,duration=10s'

70
deployment-temp.yaml Normal file
View File

@@ -0,0 +1,70 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: $APP_NAME
version: $APP_TAG
name: $APP_NAME
namespace: dl-proj #一定要写名称空间
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: $APP_NAME
strategy:
rollingUpdate:
maxSurge: 50%
maxUnavailable: 50%
type: RollingUpdate
template:
metadata:
labels:
app: $APP_NAME
version: $APP_TAG
spec:
imagePullSecrets:
- name: dockerhub-id #提前在项目下配置访问阿里云的账号密码
containers:
- image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG
name: $APP_NAME
imagePullPolicy: Always
livenessProbe: # 存活探针:失败意味着应用彻底挂了,需要重启来恢复
httpGet:
path: /test
port: 9090
initialDelaySeconds: 10 # 延迟xx秒开始执行
periodSeconds: 15 # 每隔15秒执行一次
timeoutSeconds: 10 # 10秒未返回结果则超时
failureThreshold: 10 # 探测失败后的重试次数,当达到这个次数后就判定结果为失败
# successThreshold: 5
ports:
- containerPort: 13145
protocol: TCP
resources:
limits:
cpu: 99m
memory: 65Mi
env:
- name: TZ
value: "Asia/Shanghai"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: $APP_NAME
name: $APP_NAME
namespace: dl-proj
spec:
type: NodePort
externalTrafficPolicy: Local
ports:
- name: http
protocol: TCP
port: 13145
nodePort: 13145
selector:
app: $APP_NAME

129
pom.xml
View File

@@ -5,22 +5,38 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.5</version>
<version>4.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<groupId>com.bamanker</groupId>
<artifactId>dailyLove</artifactId>
<version>0.1.6</version>
<name>dailyLove</name>
<description>dailyLove</description>
<artifactId>dailylove</artifactId>
<version>v2.4.0-native</version>
<name>dailylove</name>
<description>dailylove-forK8S</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<fastjson.version>2.0.21</fastjson.version>
<openfeign.version>3.1.5</openfeign.version>
<nacos.version>2021.1</nacos.version>
<hutool.version>5.8.10</hutool.version>
<java.version>25</java.version>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<fastjson.version>2.0.60</fastjson.version>
<openfeign.version>5.0.0</openfeign.version>
<hutool.version>5.8.25</hutool.version>
<docker.private.repository>registry.cn-chengdu.aliyuncs.com/bamanker</docker.private.repository>
<!-- <docker.private.repository>172.17.0.1:10888/my_work</docker.private.repository>-->
</properties>
<dependencies>
<dependency>
@@ -28,18 +44,16 @@
<artifactId>hutool-core</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
@@ -53,27 +67,100 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
<build>
<finalName>dailylove</finalName>
<!--指定filtering=true.maven的占位符解析表达式就可以用于它里面的文件-->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<!--为本机映像程序添加配置,生成的配置文件位于
META-INF/native-image/groupID/artifactID/native-image.properties
也可以手动配置-->
<configuration>
<mainClass>com.bamanker.dailylove.DailyLoveApplication</mainClass>
<buildArgs>
<!--开启dashboard-->
<!-- <arg>-H:DashboardDump=dailylove -H:+DashboardAll</arg>-->
<arg->-H:+ReportExceptionStackTraces</arg->
<!--开启JFR-->
<arg>--enable-monitoring=jfr</arg>
<!-- <arg>&#45;&#45;gc=G1</arg>-->
<!-- <arg>&#45;&#45;pgo</arg>-->
<arg>-Ob</arg>
<!-- <arg>-march=native</arg>-->
<!-- <arg>-H:+BuildReport</arg>-->
</buildArgs>
<!--启动详细输出-->
<verbose>true</verbose>
<!--配置jvm参数-->
<!-- <jvmArgs>
</jvmArgs>-->
<!--<agent>
<enabled>true</enabled>
<options>
<option>experimental-class-loader-support</option>
</options>
</agent>-->
</configuration>
</plugin>
<plugin>
<!--支持yaml读取pom的参数-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>25</release>
<annotationProcessors>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor
</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,14 +1,20 @@
package com.bamanker.dailylove;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author bamanker
*/
@SpringBootApplication
@EnableFeignClients
//开启定时任务
@EnableScheduling
//@ImportAutoConfiguration({FeignAutoConfiguration.class})
public class DailyLoveApplication {
public static void main(String[] args) {

View File

@@ -0,0 +1,139 @@
package com.bamanker.dailylove.config;
import cn.hutool.core.util.ClassUtil;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* 反射将所有项目类扫描加入到服务, 大力出奇迹的操作,感觉不太合适,不过先让服务跑起来
*
* @author bamanker
*/
@Component
public class ClassReflectConfig {
static boolean begin = true;
@Value("${scanclass}")
private Boolean scanclass;
@Autowired
private ThreadPoolTaskExecutor executorService;
@PostConstruct
public void init() {
if (scanclass) {
System.err.println("配置文件下 scanclass 开启了生成反射类");
} else {
System.err.println("配置文件下 scanclass 关闭了生成反射类");
}
synchronized (ClassReflectConfig.class) {
if (begin && scanclass) {
begin = false;
executorService.submit(() -> {
// {
// // 先抓取上一次的文件,生成
// try {
// BufferedReader utf8Reader = ResourceUtil
// .getUtf8Reader("classpath:/META-INF/native-image/reflect-config.json");
// String res = utf8Reader.lines().collect(Collectors.joining());
// List object = ProJsonUtil.toObject(res, List.class);
// for (Object object2 : object) {
// try {
// Map object22 = (Map) object2;
// handlerClass(Class.forName(ProMapUtil.getStr(object22, "name")));
// } catch (Exception e) {
// }
// }
// } catch (Exception e) {
// log.error("生成文件异常", e);
// }
// }
{
// 扫描系统第二级开始的包
String packageName = ClassReflectConfig.class.getPackageName();
String proPackageName = packageName.substring(0,
packageName.indexOf(".", packageName.indexOf(".") + 1));
// 可以在这个地方,添加除了服务以外其他的包,将会加入反射,以供graalvm生成配置
List<String> asList = Arrays.asList(proPackageName);
for (String spn : asList) {
try {
Set<Class<?>> doScan = ClassUtil.scanPackage(spn);
for (Class clazz : doScan) {
handlerClass(clazz);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
// handlerClass(RedisMessageListenerContainer.class);
});
}
}
}
private void handlerClass(Class clazz) {
if (clazz.equals(ClassReflectConfig.class)) {
// 跳过自己,避免形成循环
return;
}
executorService.submit(() -> {
try {
System.err.println("反射注入:" + clazz.getName());
// 生成所有的构造器
Constructor[] declaredConstructors = clazz.getDeclaredConstructors();
// 找到无参构造器然后实例化
Constructor declaredConstructor = clazz.getDeclaredConstructor();
declaredConstructor.setAccessible(true);
Object newInstance = declaredConstructor.newInstance();
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
try {
// 实例化成功,那么调用一下
method.setAccessible(true);
// graalvm必须需要声明方法
method.invoke(newInstance);
} catch (Throwable e) {
}
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
field.getType();
String name = field.getName();
field.get(newInstance);
} catch (Throwable e) {
}
}
System.err.println("反射注入完成:" + clazz.getName());
} catch (Throwable e) {
}
});
}
}

View File

@@ -5,7 +5,6 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
@Component
@RefreshScope
public class DailyLoveConfigure {
// public static String Access_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
// public static String Send_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}";

View File

@@ -8,9 +8,13 @@ import org.springframework.stereotype.Component;
@Component
public class PushTask {
@Autowired
final
PushDailyController pushDailyController;
public PushTask(PushDailyController pushDailyController) {
this.pushDailyController = pushDailyController;
}
//每日 早上7.30,晚上22点 定时推送
@Scheduled(cron = "0 30 7 * * ?")
public void scheduledPushMorning(){

View File

@@ -9,10 +9,11 @@ import com.bamanker.dailylove.service.DataRemoteClient;
import com.bamanker.dailylove.service.WechatRequestClient;
import com.bamanker.dailylove.utils.DataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -20,12 +21,17 @@ import java.util.Date;
@RestController
public class PushDailyController {
@Resource
final
DataRemoteClient dataRemoteClient;
@Resource
final
WechatRequestClient wechatRequestClient;
public PushDailyController(DataRemoteClient dataRemoteClient, WechatRequestClient wechatRequestClient) {
this.dataRemoteClient = dataRemoteClient;
this.wechatRequestClient = wechatRequestClient;
}
/**
* 推送晚安
*

View File

@@ -4,12 +4,24 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author bamanker
*/
@Slf4j
@RestController
public class TestController {
/**
* 处理GET请求的测试方法。
*
* @return 返回一个字符串,内容为"test ok!!!!!!!!",用于验证功能的正常运行。
*/
@GetMapping("/test")
public String test(){
return "test ok!!!!!!";
return "test ok!!!!!!!!";
}
}

View File

@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author bamanker
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@@ -11,4 +14,8 @@ public class DataItem {
private String value;
private String color;
}

View File

@@ -4,6 +4,9 @@ server:
spring:
application:
name: dailyLove
cloud:
refresh:
enabled: false
DL:
tianxin-key: 72fbbb9e75e338ea6a240e83972f287c
@@ -49,4 +52,6 @@ tianxin:
logging:
level:
com.bamanker.dailylove.service: debug #指定openfeign日志以什么级别监控哪个接口可多个
com.bamanker.dailylove.service: debug #指定openfeign日志以什么级别监控哪个接口可多个
scanclass: false

View File

@@ -13,7 +13,7 @@ import org.bouncycastle.util.Strings;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -25,128 +25,128 @@ import static com.bamanker.dailylove.utils.DataUtils.getBirthdays;
@Slf4j
class DailyLoveApplicationTests {
@Resource
DataRemoteClient dataRemoteClient;
String remark = "";
@Test
void test4(){
log.info("mark: {}",205%100);
}
@Test
void test3() {
//获取输入的生日
String boyBirthday = DailyLoveConfigure.Boy_Birthday;
//获取农历生日
ChineseDate chineseBir = new ChineseDate(DateUtil.parseDate(DailyLoveConfigure.Boy_Birthday));
log.info("生日的农历日期是:{}", chineseBir);
//截取日、月
String[] strings = Strings.split(boyBirthday, '-');
int chineseMonth = chineseBir.getMonth();
int chineseDay = chineseBir.getDay();
//获取当前日期的年
Calendar dateToday = Calendar.getInstance();
int todayYear = dateToday.get(Calendar.YEAR);
//把生日的年改为今年,方便计算
ChineseDate chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay,false);
//农历日期对应的阳历日期
int gregorianDay = chineseDate.getGregorianDay();
//计算时间差
long days = haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
log.info("days:{}", days);
}
/**
* 需要递归计算日期差
*
* @param chineseMonth 农历月
* @param chineseDay 农历日
* @param dateToday 今天的日期类
* @param todayYear 当前的年
* @param chineseDate 组装的待计算的新日期
* @param gregorianDay 判断是否存在农历日期的参数,-1代表今年不存在这个农历日期
* @return 计算好的天数
*/
private static long haveThisDay(int chineseMonth, int chineseDay, Calendar dateToday, int todayYear, ChineseDate chineseDate, int gregorianDay) {
//判断当前年份是否存在农历日对应的阳历日
while (gregorianDay == -1) {
//不存在,计算明年
todayYear += 1;
chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
gregorianDay = chineseDate.getGregorianDay();
}
//存在
//将农历日期改为阳历日期
Calendar gregorianbir = chineseDate.getGregorianCalendar();
//判断这个日期是否和今年是同一年
if (todayYear == dateToday.get(Calendar.YEAR)) {
//是同一年,判断这一天过了没
if (gregorianbir.get(Calendar.DAY_OF_YEAR) < dateToday.get(Calendar.DAY_OF_YEAR)) {
//这一天过了,计算明年
todayYear += 1;
chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
gregorianDay = chineseDate.getGregorianDay();
//递归计算下一年是否存在对应的阳历日
return haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
}
//没有过,直接计算
}
//不是同一年,直接计算
Date time = dateToday.getTime();
log.info("当前的日期是:{}", time);
Date time1 = gregorianbir.getTime();
log.info("下一个生日的日期:{}", time1);
return DateUtil.between(dateToday.getTime(), gregorianbir.getTime(), DateUnit.DAY);
}
@Test
void test2() {
TianXinReqParam param1 = new TianXinReqParam();
param1.setKey(DailyLoveConfigure.TianXin_Key);
param1.setCity(DailyLoveConfigure.City_ID);
param1.setType("7");
String weatherJson = dataRemoteClient.getWeather(param1);
log.info("weather:{}", weatherJson);
JSONObject resWeather = JSONObject.parseObject(weatherJson);
JSONObject result = resWeather.getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(2);
log.info("----result----:{}", result);
Weather weather = result.toJavaObject(Weather.class);
log.info("weather:{}", weather);
ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate(weather.getDate()));
System.out.println("--------------55555----------"+weather.getDate());
System.out.println("------------------------"+chineseDate);
}
@Test
void test1() {
int loveDays = getBirthdays("2023-05-14");
log.info("-------------------------------{}", loveDays);
}
public static int getLoveDays(String loveday) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
int days = 0;
try {
long time = System.currentTimeMillis() - dateFormat.parse(loveday).getTime();
days = (int) (time / (24 * 60 * 60 * 1000));
} catch (ParseException e) {
e.printStackTrace();
}
return days;
}
@Test
void contextLoads() {
// @Resource
// DataRemoteClient dataRemoteClient;
//
// String remark = "❤";
//
// @Test
// void test4(){
// log.info("mark: {}",205%100);
//
// }
// @Test
// void test3() {
//
//
// //获取输入的生日
// String boyBirthday = DailyLoveConfigure.Boy_Birthday;
// //获取农历生日
// ChineseDate chineseBir = new ChineseDate(DateUtil.parseDate(DailyLoveConfigure.Boy_Birthday));
// log.info("生日的农历日期是:{}", chineseBir);
// //截取日、月
// String[] strings = Strings.split(boyBirthday, '-');
// int chineseMonth = chineseBir.getMonth();
// int chineseDay = chineseBir.getDay();
// //获取当前日期的年
// Calendar dateToday = Calendar.getInstance();
// int todayYear = dateToday.get(Calendar.YEAR);
// //把生日的年改为今年,方便计算
// ChineseDate chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay,false);
// //农历日期对应的阳历日期
// int gregorianDay = chineseDate.getGregorianDay();
// //计算时间差
// long days = haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
// log.info("days:{}", days);
//
// }
//
// /**
// * 需要递归计算日期差
// *
// * @param chineseMonth 农历月
// * @param chineseDay 农历日
// * @param dateToday 今天的日期类
// * @param todayYear 当前的年
// * @param chineseDate 组装的待计算的新日期
// * @param gregorianDay 判断是否存在农历日期的参数,-1代表今年不存在这个农历日期
// * @return 计算好的天数
// */
// private static long haveThisDay(int chineseMonth, int chineseDay, Calendar dateToday, int todayYear, ChineseDate chineseDate, int gregorianDay) {
// //判断当前年份是否存在农历日对应的阳历日
// while (gregorianDay == -1) {
// //不存在,计算明年
// todayYear += 1;
// chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
// gregorianDay = chineseDate.getGregorianDay();
// }
// //存在
// //将农历日期改为阳历日期
// Calendar gregorianbir = chineseDate.getGregorianCalendar();
// //判断这个日期是否和今年是同一年
// if (todayYear == dateToday.get(Calendar.YEAR)) {
// //是同一年,判断这一天过了没
// if (gregorianbir.get(Calendar.DAY_OF_YEAR) < dateToday.get(Calendar.DAY_OF_YEAR)) {
// //这一天过了,计算明年
// todayYear += 1;
// chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
// gregorianDay = chineseDate.getGregorianDay();
// //递归计算下一年是否存在对应的阳历日
// return haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
// }
// //没有过,直接计算
// }
// //不是同一年,直接计算
// Date time = dateToday.getTime();
// log.info("当前的日期是:{}", time);
// Date time1 = gregorianbir.getTime();
// log.info("下一个生日的日期:{}", time1);
// return DateUtil.between(dateToday.getTime(), gregorianbir.getTime(), DateUnit.DAY);
// }
//
// @Test
// void test2() {
//
// TianXinReqParam param1 = new TianXinReqParam();
// param1.setKey(DailyLoveConfigure.TianXin_Key);
// param1.setCity(DailyLoveConfigure.City_ID);
// param1.setType("7");
// String weatherJson = dataRemoteClient.getWeather(param1);
// log.info("weather:{}", weatherJson);
// JSONObject resWeather = JSONObject.parseObject(weatherJson);
// JSONObject result = resWeather.getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(2);
// log.info("----result----:{}", result);
// Weather weather = result.toJavaObject(Weather.class);
// log.info("weather:{}", weather);
// ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate(weather.getDate()));
// System.out.println("--------------55555----------"+weather.getDate());
// System.out.println("------------------------"+chineseDate);
//
//
// }
//
//
// @Test
// void test1() {
// int loveDays = getBirthdays("2023-05-14");
// log.info("-------------------------------{}", loveDays);
// }
//
// public static int getLoveDays(String loveday) {
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// int days = 0;
// try {
// long time = System.currentTimeMillis() - dateFormat.parse(loveday).getTime();
// days = (int) (time / (24 * 60 * 60 * 1000));
//
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return days;
// }
//
// @Test
// void contextLoads() {
// TianXinReqParam param1 = new TianXinReqParam();
// param1.setKey(DailyLoveConfigure.TianXin_Key);
// param1.setCity(DailyLoveConfigure.City_ID);
@@ -203,6 +203,6 @@ class DailyLoveApplicationTests {
// log.info("resultVo:{}", resultVo);
}
// }
}

View File

@@ -1,2 +0,0 @@
nohup java -Xms32M -Xmx32M -jar /home/dailyLove/dailyLove-0.1.6.jar >> /home/dailyLove/log/runout.log 2>&1 &
tail -f /home/dailyLove/log/runout.log