查看“Spring Boot 微服务极简化开发”的源代码
←
Spring Boot 微服务极简化开发
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
使用 sprint Boot 框架,结合自定义类,实现 webservice 极简化开发。 === Setup === ==== Project Setting ==== <small><nowiki>Modules Source Folders: src/main/java Resource Folders: src/main/resources Test Source Folders: src/test/java Test Resource Folders: src/test/resources Excluded Folders: target</nowiki></small> ==== pom ==== <small><nowiki><!-- spring-boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.2</version> <relativePath/> </parent> <dependencies> <!-- spring-boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--log4j--> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!--slf4j--> <!-- Conflicts with spring boot <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>2.0.9</version> </dependency> <!--Json--> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.9</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.28</version> </dependency> <!--h2--> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>2.1.212</version> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </dependencies></nowiki></small> ==== application.yaml ==== src/main/resources <small><nowiki>spring.application.name: SprintBootDemo spring.profiles.active: production server: port: 8080 spring.thymeleaf: mode: HTML cache: false encoding: UTF-8 enabled: true prefix: classpath:/templates/ suffix: .html</nowiki></small> ==== index.html ==== src/main/resources/static // 更改需重启 <small><nowiki><html> <p>This webservice is running...</p> </html></nowiki></small> ==== com.udef ==== BASE/CNFYAML/DB/SQLData ==== etc ==== log4j.properties/sysdb.yaml/db.yaml ==== config ==== sql1.yaml // 更改不需重启 === Service === src/main/java/SprintBoot/SprintBootStart.java <small><nowiki>package SprintBoot; import com.udf.SQLData; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SprintBootStart { public static SQLData[] sql = new SQLData[10]; public SprintBootStart() { sql[0] = new SQLData("h2local", "db.yaml"); } public static void main(String[] args) { SpringApplication.run(SprintBootStart.class, args); } }</nowiki></small> src/main/java/SprintBoot/sql1/sql1.java <small><nowiki>package SprintBoot; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.LinkedHashMap; import java.util.Map; import com.udf.SQLData; import static SprintBoot.SprintBootStart.sql; @RestController @RequestMapping("/sql") public class sql1 { String appName; public sql1() { appName = "sql"; } @RequestMapping(value = "/get1", method = RequestMethod.GET) public Map<String, Object> getTest1() { //BASE.UDEFLOG = "ALL"; SQLData sql1 = sql[0]; sql1.setSQLYaml("config/sql1.yaml"); Map<String, String> m1 = new LinkedHashMap<>(); // get data m1.put("api", "SE_PROD"); m1.put("where.status", "1"); m1.put("where.ca", "in ('LRL', 'adam')"); return sql1.SQL(m1); } }</nowiki></small> 运行调试没问题的话,就可以打 jar 包了。 === package === ==== set main class ==== src/main/resources/META-INF/MANIFEST.MF Manifest-Version: 1.0 Main-Class: SprintBoot.SprintBootStart ==== maven build ==== maven -> XXX —> Lifecycle -> package -> build ==== RUN ==== java -jar XXX.jar === Error === ==== Artifact ==== Project Structure -> Artifact Build Artifact java -jar XXX.jar -> Error: No active profile set, falling back to 1 default profile: "default" Solution: maven package ==== 没有主清单属性 ==== 1. pom 中未引入 spring-boot-maven-plugin 2. MANIFEST.MF 中启动类设置错误(若只有一个 main,倒也无妨) 3. MF 文件也可通过 Project Setting/Artifacts 生成 ==== 找不到或无法加载主类 ==== // 明明有,但是却无法 run/debug reload all maven [[分类:Develop]] [[分类:Java]]
返回
Spring Boot 微服务极简化开发
。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
目录
文章分类
侧边栏
帮助
工具
链入页面
相关更改
特殊页面
页面信息