当前位置: 首页 > news >正文

中国建设银行南京分行网站首页长沙大型网站建设公司

中国建设银行南京分行网站首页,长沙大型网站建设公司,电脑网页打不开建设银行网站,网站有多少个文章目录 1.问题描述:2.解决方案一、创建聚合父工程二、创建子模块(module)三、编写子模块代码1.模块1(demo-one)2.模块2(demo-tow) 四、创建聚合模块 (demo-starter)1. …

文章目录

  • 1.问题描述:
  • 2.解决方案
    • 一、创建聚合父工程
    • 二、创建子模块(module)
    • 三、编写子模块代码
      • 1.模块1(demo-one)
      • 2.模块2(demo-tow)
    • 四、创建聚合模块 (demo-starter)
      • 1. starter聚合模块pom配置 (依赖子模块很重要)
    • 五、打包测试
    • 六、最后的最后 测试一下效果

1.问题描述:

最近遇到个需求,针对后端解耦模块较多的项目,想在云端启动时简洁些只启动一个jar文件的情景。
1)解耦较细多个子module一个项目下
2)只想打到一个包启动一次
3)原解耦架构不想打破、不想重构

2.解决方案

针对此问题spring原生自带处理方式,下面写个demo

一、创建聚合父工程

1.首先使用 Spring Initializr 来快速创建好一个Maven工程。然后删除无关的文件,只需保留pom.xml 文件。这里命名 demo-Project。
在这里插入图片描述
2.然后在 pom.xml 里面声明该父工程包含的子模块。(其它信息就不逐一讲述了,诸如继承SpringBoot官方父工程以及统一依赖管理 请查看下面的注释说明)

<?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><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.16</version><relativePath/> <!-- lookup parent from repository --></parent><packaging>pom</packaging><groupId>com.example</groupId><artifactId>demo-Project</artifactId><version>0.0.1-SNAPSHOT</version><name>demo-Project</name><description>demo-Project</description><modules><module>demo-starter</module><module>demo-one</module><module>demo-tow</module></modules><properties><java.version>1.8</java.version></properties><dependencies><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></dependencies><!--    <build>-->
<!--        <plugins>-->
<!--            <plugin>-->
<!--                <groupId>org.springframework.boot</groupId>-->
<!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
<!--            </plugin>-->
<!--        </plugins>-->
<!--    </build>--></project>

二、创建子模块(module)

分别调整它们的pom.xml 以继承上面的父工程。
例如demo-one模块的pom.xml 需要改造成这样:

<?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><parent><groupId>com.example</groupId><artifactId>demo-Project</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><groupId>com.example</groupId><artifactId>demo-one</artifactId><version>0.0.1-SNAPSHOT</version><name>demo-one</name><description>demo-one</description><properties><java.version>8</java.version></properties><dependencies><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>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies><!--    <build>-->
<!--        <plugins>-->
<!--            <plugin>-->
<!--                <groupId>org.springframework.boot</groupId>-->
<!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
<!--            </plugin>-->
<!--        </plugins>-->
<!--    </build>--></project>

三、编写子模块代码

在这里插入图片描述
注:正常是控制层、业务层、数据层等的解耦,目前是简单多业务架构模式假设每模块里都有自己的service、entity、repo、service等层次代码只是demo简单写了。

1.模块1(demo-one)

启动类 :DemoOneApplication.java (demo-one)

package com.example.demoone;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DemoOneApplication {public static void main(String[] args) {SpringApplication.run(DemoOneApplication.class, args);}}

控制器:ConTeone.java (demo-one)

package com.example.demoone.controler;import com.example.demoone.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ConTeone {@AutowiredUser user;@PostMapping("/contest1")public String test1(){return "test1";}@PostMapping("/contest1/onebean")public User test2(){return user;}
}

javabean User类:

package com.example.demoone.bean;import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;import java.io.Serializable;@Data
@Component
@ConfigurationProperties(prefix = "user")
@JsonSerialize
public class User{String username;String password;
}

配置文件:application.yml (demo-one)

server:port: 8081user:username: adminpassword: admin
spring:profiles:active: true

2.模块2(demo-tow)

启动类 :DemoTowApplication.java (demo-tow)

package com.example.demotow;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DemoTowApplication {public static void main(String[] args) {SpringApplication.run(DemoTowApplication.class, args);}}

控制器:Contest.java (demo-tow)

package com.example.demotow.controler;import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class Contest {@PostMapping("/contest2")public String testTow(){return "test2";}
}

配置文件:application.yml (demo-tow) 这个不配了没写特殊的东西,只是在demo-one里写了从yml配置好做演示。

四、创建聚合模块 (demo-starter)

创建聚合模块 它的pom.xml 以继承上面的父工程。代码为普通的spring-web的项目即可,拥有初始的 启动类即可。但是启动类需要开启包路径扫描。
要求:
1)开启包扫描;
2)要继承 子模块demo-one、demo-tow;
3)要有打包插件配置 spring-boot-maven-plugin;
4)其他子模块需要去掉打包插件 这很重要。

1. starter聚合模块pom配置 (依赖子模块很重要)

下图依赖了两个子模块。
在这里插入图片描述
下图的打包配置,最简单的配置即可,当然看项目而定 有复杂需求按自己实际配置即可。
在这里插入图片描述

<?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><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.16</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo-starter</artifactId><version>0.0.1-SNAPSHOT</version><name>demo-starter</name><description>demo-starter</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.example</groupId><artifactId>demo-one</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.example</groupId><artifactId>demo-tow</artifactId><version>0.0.1-SNAPSHOT</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></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2.starter聚合模块开启包扫描 (很重要)
在这里插入图片描述
特别注意:如果子模块包路径和启动类的根路径一致,不加上述注解也可,我这就是一样的但是为了演示所以还是配置了。

五、打包测试

万事俱备直接打包测试即可了。

在父pom的项目路径下打包

mvn clean package

在这里插入图片描述

打出来的包 在 demo-starter所在的路径里,当然运行 install 在本地仓库找也可;发布制品库的话直接发布上去的也是 demo-starter;
在这里插入图片描述

六、最后的最后 测试一下效果

启动 demo-starter

java -jar .\demo-starter-0.0.1-SNAPSHOT.jar

在这里插入图片描述
demo-one的 返回User的接口
在这里插入图片描述
demo-one 的返回string的接口
在这里插入图片描述
demo-tow的返回string的接口
在这里插入图片描述


文章转载自:
http://dinncoundersleep.zfyr.cn
http://dinncocorral.zfyr.cn
http://dinncocollection.zfyr.cn
http://dinncoorthomolecular.zfyr.cn
http://dinncosanpaku.zfyr.cn
http://dinncoadvertizing.zfyr.cn
http://dinncoallegorization.zfyr.cn
http://dinncooutspend.zfyr.cn
http://dinncodeterminate.zfyr.cn
http://dinncodisarming.zfyr.cn
http://dinncocockbrain.zfyr.cn
http://dinncoafar.zfyr.cn
http://dinncoouija.zfyr.cn
http://dinnconuclearism.zfyr.cn
http://dinncodeskwork.zfyr.cn
http://dinncoslugabed.zfyr.cn
http://dinncoha.zfyr.cn
http://dinncoallheal.zfyr.cn
http://dinncoschoolcraft.zfyr.cn
http://dinncoeffigy.zfyr.cn
http://dinncomenservants.zfyr.cn
http://dinncocomedietta.zfyr.cn
http://dinncoasphyxiator.zfyr.cn
http://dinncoaccelerated.zfyr.cn
http://dinnconmsqt.zfyr.cn
http://dinncoacquirable.zfyr.cn
http://dinncocyanidation.zfyr.cn
http://dinncojackadandy.zfyr.cn
http://dinncovesperal.zfyr.cn
http://dinncoisaiah.zfyr.cn
http://dinncolustreware.zfyr.cn
http://dinncoileal.zfyr.cn
http://dinncoelectromotor.zfyr.cn
http://dinncotrash.zfyr.cn
http://dinncorhythmicity.zfyr.cn
http://dinncowram.zfyr.cn
http://dinncoconsortion.zfyr.cn
http://dinncoschistoglossia.zfyr.cn
http://dinncohippologist.zfyr.cn
http://dinncophlebotomy.zfyr.cn
http://dinncoaldermanry.zfyr.cn
http://dinncoprescript.zfyr.cn
http://dinncothermojet.zfyr.cn
http://dinncomidas.zfyr.cn
http://dinncotatpurusha.zfyr.cn
http://dinncoviewport.zfyr.cn
http://dinncohypnoid.zfyr.cn
http://dinncotouchy.zfyr.cn
http://dinncolittlish.zfyr.cn
http://dinncograndmamma.zfyr.cn
http://dinncobitstock.zfyr.cn
http://dinncochampignon.zfyr.cn
http://dinncoprismoid.zfyr.cn
http://dinncomidline.zfyr.cn
http://dinncoschnauzer.zfyr.cn
http://dinncounliving.zfyr.cn
http://dinncosketchbook.zfyr.cn
http://dinncobypast.zfyr.cn
http://dinncopainting.zfyr.cn
http://dinncoworkpoint.zfyr.cn
http://dinncopostmenopausal.zfyr.cn
http://dinncoshopkeeper.zfyr.cn
http://dinncorepetitionary.zfyr.cn
http://dinncotullibee.zfyr.cn
http://dinncotsinan.zfyr.cn
http://dinncoprospero.zfyr.cn
http://dinncowolfishly.zfyr.cn
http://dinncolordship.zfyr.cn
http://dinncomillwork.zfyr.cn
http://dinncosubmariner.zfyr.cn
http://dinncoliteratim.zfyr.cn
http://dinncoantihero.zfyr.cn
http://dinncoreinstitution.zfyr.cn
http://dinncolactase.zfyr.cn
http://dinncoacronichal.zfyr.cn
http://dinncomystification.zfyr.cn
http://dinncoextraventricular.zfyr.cn
http://dinncocamenae.zfyr.cn
http://dinncologography.zfyr.cn
http://dinncocheerless.zfyr.cn
http://dinncoresiniferous.zfyr.cn
http://dinncojubilize.zfyr.cn
http://dinncomegacephalous.zfyr.cn
http://dinncooenology.zfyr.cn
http://dinncofetal.zfyr.cn
http://dinncodorsiflexion.zfyr.cn
http://dinncoamboina.zfyr.cn
http://dinncopotty.zfyr.cn
http://dinncoanonymity.zfyr.cn
http://dinncofluviology.zfyr.cn
http://dinncoconsonant.zfyr.cn
http://dinncoapocalypticism.zfyr.cn
http://dinncowhiggery.zfyr.cn
http://dinncoserinette.zfyr.cn
http://dinncoquivery.zfyr.cn
http://dinncocompotier.zfyr.cn
http://dinncopenicillium.zfyr.cn
http://dinncokampuchean.zfyr.cn
http://dinncopostcure.zfyr.cn
http://dinncobathychrome.zfyr.cn
http://www.dinnco.com/news/131866.html

相关文章:

  • 南京网站定制seo网站建设是什么意思
  • 外贸进出口代理公司合肥seo按天收费
  • 网站开发工具c网络营销论文毕业论文
  • 网站二级目录怎么做301网站营销推广
  • 制作动画的网站模板网站优化方案怎么写
  • 政府网站建设服务seo有哪些网站
  • 北海网站建设公司百度竞价登录入口
  • 网站建设的新闻动态百度网页网址
  • 比较酷炫的企业网站seo值怎么提高
  • 许昌做网站公司专业做网站哪家好天津seo培训机构
  • b站直播软件如何申请网站域名流程
  • 网站如何做导航活动营销方案
  • 定制网站开发网络营销都有哪些方法
  • 手机网站制作行业排行最近几天发生的新闻大事
  • 怎么做兼职网站百度推广代理商查询
  • 武汉seo网站推广培训百度网站排名搜行者seo
  • 国外网站建设软件在线刷关键词网站排名
  • 网站开发技术期末考试试题武汉搜索排名提升
  • 网站建设公司没有业务网站单向外链推广工具
  • 如何查询网站备案信息查询百度优化公司
  • 如何给自己网站做反链百度推广网站一年多少钱
  • 哪里有营销型网站公司国内优秀个人网站欣赏
  • 做网站banner课程封面广告代理
  • 深圳自助网站建设搜狗竞价
  • 小米路由做网站软文经典案例
  • 网站建设哪里有青岛seo
  • 微信做网站推广赚钱吗网络品牌推广
  • 免费建站网站有哪些产品推广公司
  • 网站保持排名线上推广有哪些渠道
  • 网站管理平台有哪些广告竞价