我以这种方式在spring boot应用程序中有一个通用的jar文件,
package com.acc.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
@ComponentScan(basePackages = {"com.acc.api","service"})
public class ApicoreApplication {
public static void main(String[] args) {
ApplicationContext applicationContext = SpringApplication.run(ApicoreApplication.class, args);
for (String name: applicationContext.getBeanDefinitionNames()) {
System.out.println(name);
}
}
}
其中的组件是,
package com.acc.api.core.utils;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class AccUtil {
@Autowired
private WebServiceEngine engine;
}
其中 WebServiceEngine 是我调用的第三方 api。
我的 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 http://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.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.acc.api</groupId>
<artifactId>apicore</artifactId>
<version>0.0.1</version>
<name>apicore</name>
<description>apicore</description>
<properties>
<java.version>1.8</java.version>
</properties>
直到这很好,项目正在编译,jar 正在目标文件夹中创建。
慕码人8056858
慕容708150
噜噜哒
相关分类