-
在resources中添加tarsjava.conf文件
<tars>
<application>
enableset=n
setdivision=NULL
<client>
locator=
sync-invoke-timeout=20000
async-invoke-timeout=20000
stat=tars.tarsstat.StatObj
modulename=TestHttp.HelloJavaServer
</client>
<server>
node=
lognum=10
logLevel=DEBUG
deactivating-timeout=3000
activating-timeout=10000
app=TestHttp
server=HelloHttp
localip=127.0.0.1
local=tcp -h 127.0.0.1 -p 42460 -t 10000
basepath=.
datapath=.
logpath=.
loglevel=DEBUG
logsize=15M
log=tars.tarslog.LogObj
config=tars.tarsconfig.ConfigObj
notify=tars.tarsnotify.NotifyObj
sessiontimeout=120000
sessioncheckinterval=60000
tcpnodelay=true
udpbuffersize=8192
charsetname=UTF-8
backupfiles=conf
packageFormat=jar
<TestHttp.HelloHttp.HttpObjAdapter>
allow
endpoint=tcp -h 127.0.0.1 -p 17608 -t 60000
maxconns=100000
protocol=not_tars
queuecap=50000
queuetimeout=20000
servant=TestHttp.HelloHttp.HttpObj
threads=5
</TestHttp.HelloHttp.HttpObjAdapter>
</server>
</application>
</tars>
-
在yml中添加
tars:
enabled: false
-
添加类
public class HierwaySpringApplication {
public static Boolean value = false;
//bootstrap.yml为上方的yml文件 名字不同的请手动更改
public static ConfigurableApplicationContext run(Class<?> primarySource,String... args) {
System.setProperty("nacos.logging.default.config.enabled", "false");
String smlPath = "";
if (FileUtil.exist("./bootstrap.yml")){
smlPath = FileUtil.getAbsolutePath("./bootstrap.yml");
}
if (FileUtil.exist(System.getProperty("user.dir")+"/config/bootstrap.yml")){
smlPath = System.getProperty("user.dir")+"/config/bootstrap.yml";
}
String tarsEnabled = System.getProperty("spring.tars.enabled");
if (StringUtils.isEmpty(tarsEnabled)){
value = (Boolean) getYmlPropertyValue(smlPath,"spring.tars.enabled");
}else{
value = Boolean.valueOf(tarsEnabled);
}
System.out.println("----------------tarsEnable----------------------"+ value);
if (!value){
String path = "";
if (FileUtil.exist("./tarsjava.conf")){
path = FileUtil.getAbsolutePath("./tarsjava.conf");
}
if (FileUtil.exist(System.getProperty("user.dir")+"/config/tarsjava.conf")){
path = System.getProperty("user.dir")+"/config/tarsjava.conf";
}
if (path==""){
URL url=primarySource.getProtectionDomain().getCodeSource().getLocation();
path=url.getPath();
int index = path.lastIndexOf("/");
path = path.substring(0,index);
if (FileUtil.exist(path+"/config/tarsjava.conf")){
path = FileUtil.getAbsolutePath(path+"/config/tarsjava.conf");
}
}
System.out.println("jar包目录:"+path);
System.out.println("----------------path----------------------"+path);
System.setProperty("config", path);
}
return SpringApplication.run(primarySource,args);
}
public static Object getYmlPropertyValue(String path,String key) {
Properties properties = null;
try {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
if (StringUtils.isEmpty(path)){
Resource resource = new ClassPathResource("bootstrap.yml");
yamlFactory.setResources(resource);
}else{
yamlFactory.setResources(new FileSystemResource(path));
}
properties = yamlFactory.getObject();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return properties.get(key);
}
}
-
启动类调用
public static void main(String[] args) {
HierwaySpringApplication.run(AssetManageApplication.class);
if (!HierwaySpringApplication.value){
ScheduledServiceMngr.getInstance().shutdown();
}
}
-
打包成可在tars上运行和正常环境运行的包可参考java 打包发布