zhangxu
2022-07-20 6d74163dc2d9675d0af367c86a0c9c70cbd18cd3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.hx.phip;
 
import com.hx.util.AesUtil;
import com.hx.phip.config.UniqueNameGenerator;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
 
@SpringBootApplication
@MapperScan({"com.gitee.sunchenbin.mybatis.actable.dao.*","com.hx.phip.dao.*"})
@ComponentScan(basePackages = {"com.gitee.sunchenbin.mybatis.actable.manager.*","com.hx.phip.*","com.hx.common.service.impl","com.hx.redis","com.hx.mybatis.aes.springbean"},nameGenerator = UniqueNameGenerator.class)
@ServletComponentScan
//@EnableScheduling
@EnableDiscoveryClient
@EnableFeignClients
public class PhiPlatformUserApplication extends SpringBootServletInitializer implements CommandLineRunner {
 
    public static void main(String[] args) {
 
        //获取项目部署路径
        String jarWholePath = PhiPlatformUserApplication.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        /*try {
            jarWholePath = java.net.URLDecoder.decode(jarWholePath, "UTF-8");
            System.setProperty("address.jarWholePath", jarWholePath);
        } catch (UnsupportedEncodingException e) { System.out.println(e.toString()); }
        String jarPath = new File(jarWholePath).getParentFile().getAbsolutePath();
        System.setProperty("address.jarPath", jarPath);*/
 
        if(System.getProperty("os.name").contains("dows")) {
            jarWholePath = jarWholePath.substring(1,jarWholePath.length());
        }
        if(jarWholePath.contains("jar")) {
            jarWholePath = jarWholePath.substring(0,jarWholePath.lastIndexOf("."));
            jarWholePath = jarWholePath.substring(0,jarWholePath.lastIndexOf("/"));
        }
        jarWholePath = jarWholePath.replace("target/classes/", "").replace("file:","");
        System.setProperty("address.jarPath",jarWholePath );
 
        //设置配置文件项加密密钥(放在这里使加密密钥和密文分开)
        System.setProperty("jasypt.encryptor.password", AesUtil.SECRET);
        SpringApplication.run(PhiPlatformUserApplication.class, args);
    }
 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(PhiPlatformUserApplication.class);
    }
 
    @Override
    public void run(String... args) {
        System.out.println("SpringBoot is Running...");
    }
}