/* * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package top.continew.admin; import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.net.NetUtil; import cn.hutool.core.util.URLUtil; import cn.hutool.extra.spring.SpringUtil; import com.alicp.jetcache.anno.config.EnableMethodCache; import com.github.xiaoymin.knife4j.spring.configuration.Knife4jProperties; import io.swagger.v3.oas.annotations.Hidden; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.dromara.x.file.storage.spring.EnableFileStorage; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootVersion; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import top.continew.admin.common.context.UserContext; import top.continew.admin.common.context.UserContextHolder; import top.continew.starter.core.autoconfigure.application.ApplicationProperties; import top.continew.starter.core.util.SpringUtils; import top.continew.starter.extension.crud.annotation.EnableCrudApi; import top.continew.starter.web.annotation.EnableGlobalResponse; import top.continew.starter.web.model.R; /** * 启动程序 * * @author Charles7c * @since 2022/12/8 23:15 */ @Slf4j @EnableCrudApi @EnableGlobalResponse @EnableFileStorage @EnableMethodCache(basePackages = "top.continew.admin") @EnableFeignClients @RestController @SpringBootApplication @RequiredArgsConstructor public class ContiNewAdminApplication implements ApplicationRunner { private final ApplicationProperties applicationProperties; private final ServerProperties serverProperties; private final ThreadPoolTaskExecutor threadPoolTaskExecutor; public static void main(String[] args) { SpringApplication.run(ContiNewAdminApplication.class, args); } @Hidden @SaIgnore @GetMapping("/") public R index() { return R.ok(applicationProperties); } @Override public void run(ApplicationArguments args) { String hostAddress = NetUtil.getLocalhostStr(); Integer port = serverProperties.getPort(); String contextPath = serverProperties.getServlet().getContextPath(); String baseUrl = URLUtil.normalize("%s:%s%s".formatted(hostAddress, port, contextPath)); log.info("--------------------------------------------------------"); log.info("{} server started successfully.", applicationProperties.getName()); log.info("ContiNew Starter: v{} (Spring Boot: v{})", SpringUtil .getProperty("application.starter"), SpringBootVersion.getVersion()); log.info("当前版本: v{} (Profile: {})", applicationProperties.getVersion(), SpringUtil .getProperty("spring.profiles.active")); log.info("服务地址: {}", baseUrl); Knife4jProperties knife4jProperties = SpringUtil.getBean(Knife4jProperties.class); if (!knife4jProperties.isProduction()) { log.info("接口文档: {}/doc.html", baseUrl); } log.info("吐槽广场: https://continew.top/docs/admin/issue-hub.html"); log.info("常见问题: https://continew.top/docs/admin/faq.html"); log.info("更新日志: https://continew.top/docs/admin/changelog/"); log.info("ContiNew Admin: 持续迭代优化的,高质量多租户中后台管理系统框架"); log.info("--------------------------------------------------------"); UserContext userContext = new UserContext(); userContext.setId(222L); UserContextHolder.setContext(userContext); log.info("userId: {}", UserContextHolder.getUserId()); SpringUtils.getProxy(this).async(); } @Async public void async() { log.info("async: {}", UserContextHolder.getUserId()); } }