有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Spring中实例化Util类

Spring中是否有任何注释来实例化util类。我有一个由服务层使用的util类

Util类

Class CipherUtil {
  private static final String  SECRET_KEY = "sEcrEtkEy";
  private static Cipher cipher;
  private static SecretKeySpec secretKeySpec;

  public CipherUtil() {
    //initilize cipher and secretKeySpec properties
  }

  public static String encrypt(String plainText) { ... }

  public static String decrypt(String encryptedText) { ... }
}

服务级别

Class MyService {
  @Autowired OtherService otherService;

  public void doSomething() {
      //CipherUtil is null
      String decryptedMsg = CipherUtil.encrypt("Hello World!!!"); 
  }
}

在方法中使用之前,我如何告诉Spring创建CipherUtil类


共 (0) 个答案