Skip to content

是不是没办法使用在spring容器内的IEncryptor? #5

@xxyz30

Description

@xxyz30

我自定义了个Encryptor,且使用了Spring容器的注入

@Component
public class Encryptor implements IEncryptor {

    @Autowired
    private PooledPBEStringEncryptor encryptor;

    @Autowired
    private IUserLogService userLogService;

    @Override
    public String encrypt(Object o, String s) throws Exception {
        userLogService.save(new UserLog());
        return encryptor.encrypt(o.toString());
    }

    @Override
    public String decrypt(Object o, String s) throws Exception {
        userLogService.save(new UserLog());
        return encryptor.decrypt(o.toString());
    }
}

然后就会空指针,因为这里
图片

直接使用了newInstance(),所以不在spring管理里。
是不是把这个defaultEncryptor字段的类型直接改成IEncryptor会比较好?
图片

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions