如何在springboot中使用自定义自定义类加载器

时间:2018-06-26 17:07:21

标签: spring spring-boot encryption classloader obfuscation

如何在春季启动时使用自定义类加载器加载bean

我需要加密spring boot项目。

起初我尝试使用 proguard ,但是失败了,因为spring使用了大量的注解,并且具有 DI

然后我尝试使用自定义类加载器。我想先加密我的类文件,然后使用我的自定义类加载器加载加密的类文件,然后解密。

这是我的演示:https://github.com/CaiBaoHong/boot-by-custom-loader

启动时失败:

import numpy as np
import matplotlib.pyplot as plt
from numpy.random import random as rng

def Brownian_motion(steps):
    """
    this is a random walk function
    define the number of steps to be taken as a integer value
    """
    #these are the random numbers
    steps_x = rng(steps)
    steps_y = rng(steps)

    #Here I change the random numbers to 1 or -1
    pace_x = (steps_x < 0.5)
    for i in pace_x:
        if i == False:
            pace_x[i] = -1
        else:
            pace_x[i] = 1
        return pace_x

    pace_y = (steps_y < 0.5)
    for i in pace_y:
        if i == False:
            pace_y[i] = -1
        else:
            pace_x[i] = 1
        return pace_y

    plt.plot(np.cumsum(pace_x), np.cumsum(pace_y))
    plt.show()

Brownian_motion(500)

ConfigServletWebServerApplicationContext : 
  Exception encountered during context initialization - cancelling refresh attempt: 
    org.springframework.beans.factory.UnsatisfiedDependencyException: 
      Error creating bean with name 'methodValidationPostProcessor' defined in class path resource 
        [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: 
          Unsatisfied dependency expressed through method 'methodValidationPostProcessor' parameter 0; 
          nested exception is 
            org.springframework.beans.factory.CannotLoadBeanClassException: 
              Error loading class [com.abc.bootbycustomloader.controller.UserController] 
              for bean with name 'userController' defined in file 
                [D:\code\boot-by-custom-loader\out\production\classes\com\abc\bootbycustomloader\controller\UserController.class]: problem with class file or dependent class; 
                  nested exception is java.lang.LinkageError: loader (instance of  com/abc/bootbycustomloader/loader/MyClassLoader): 
                  attempted  duplicate class definition for name: 
                  "com/abc/bootbycustomloader/controller/UserController"

0 个答案:

没有答案