结合nexus 建工具类 方便服务调用工具类

结合nexus 建工具类 方便服务调用工具类
主要目的是测试引用外部依赖的公共方法。
写了个小例子,项目中的代码无实际意义。

新建工具类

  1. 新建TimeUnit类

import java.time.LocalDateTime;

/**
 * @author qeq
 * @date 2022-11-15 09:20
 */
public class TimeUnit {
    public String getTime(){
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int monthValue = now.getMonthValue();
        int dayOfMonth = now.getDayOfMonth();
        int hour = now.getHour();
        int minute = now.getMinute();
        int second = now.getSecond();
        String str = year + "-" + monthValue + "-" + dayOfMonth + " " + hour + ":" + minute + ":" + second;
        return str;
    }

    public static void main(String[] args) {
        TimeUnit timeUnit = new TimeUnit();
        String time = timeUnit.getTime();
        System.out.println(time);
    }
}
  1. 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.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.common</groupId>
    <artifactId>common</artifactId>
    <version>0.0.1</version>
    <name>common</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>


    <!--配置当前工程保存在私服中的具体位置-->
    <distributionManagement>
        <repository>
            <!--和maven/settings.xml中server中的id一致,表示使用该id对应的用户名和密码-->
            <id>test-release</id>
            <!--release版本上传仓库的具体地址-->
            <url>http://192.168.88.100:8081/repository/test-release/</url>
        </repository>
        <snapshotRepository>
            <!--和maven/settings.xml中server中的id一致,表示使用该id对应的用户名和密码-->
            <id>test-snapshot</id>
            <!--snapshot版本上传仓库的具体地址-->
            <url>http://192.168.88.100:8081/repository/test-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

请根据自己私服配置,更改私服的配置项,build构建小编踩了坑。

新建测试项目

  1. 新建一个服务,引入公共依赖
    在这里插入图片描述
  <dependency>
            <groupId>com.common</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1</version>
        </dependency>
  1. nexus 上传的依赖:
    在这里插入图片描述

  2. 编写测试controller


import com.common.common.util.TimeUnit;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qeq
 * @date 2022-10-21 14:21
 */
@RestController
@RequestMapping("/testController")
public class TestController {

    /**
     *  127.0.0.1:8080/testController/test
     * @author qeq
     * @date 2022/10/21 14:22
     * @return String
     **/
    @RequestMapping("test")
    public String test(){
        TimeUnit timeUnit = new TimeUnit();
        String time = timeUnit.getTime();
        return time;
    }
}

  1. 测试之:
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值