在SpringJava8中,是否可以从函数接口访问服务类方法?

在SpringJava8中,是否可以从函数接口访问服务类方法?,java,spring,functional-interface,Java,Spring,Functional Interface,我想从SpringJava8中的函数接口访问服务类方法。可能吗? public interface UserProfile extends Supplier<UserProfileDto> { // This is working static UserProfile getMyId() { return () -> new UserProfileDto( Securit

我想从SpringJava8中的函数接口访问服务类方法。可能吗?

public interface UserProfile extends Supplier<UserProfileDto> {

//  This is working
    static UserProfile getMyId() {
        return () ->
                new UserProfileDto(
                        SecurityContextHolder.getContext().getAuthentication().getName(),
                        "", "", "");
    }

    static UserProfile getMyProfile() {
        return () -> 
    }
}

@Service("userProfileService")
public class UserProfileServiceImpl implements UserProfileService {

    private final UserProfileRepo userProfileRepo;

    @Autowired
    public UserProfileServiceImpl(@Qualifier("userProfileSql") UserProfileRepo userProfileRepo) {
        this.userProfileRepo = userProfileRepo;
    }

    @Override
    public Optional<UserProfileDto> getUserProfileById(String userId) {
        return userProfileRepo.selectUserProfileById(userId);
    }
}
公共接口用户配置文件扩展了供应商{
//这是有效的
静态UserProfile getMyId(){
返回()->
新UserProfileDto(
SecurityContextHolder.getContext().getAuthentication().getName(),
"", "", "");
}
静态UserProfile getMyProfile(){
返回()->
}
}
@服务(“用户档案服务”)
公共类UserProfileServiceImpl实现UserProfileService{
私有最终用户配置文件repo UserProfileRepo;
@自动连线
公共UserProfileServiceImpl(@Qualifier(“userProfileSql”)UserProfileRepo UserProfileRepo){
this.userProfileRepo=userProfileRepo;
}
@凌驾
公共可选getUserProfileById(字符串用户ID){
返回userProfileRepo。选择userprofilebyid(userId);
}
}

我想在UserProfile中的getMyProfile()中调用服务类方法“getUserProfileById(SecurityContextHolder.getContext().getAuthentication().getName())”。可能吗?

否您无法从功能接口访问服务类方法

否不可能。否。这是一种接口方法,因此不需要。您可以在
UserProfile
中定义类型为
Function
的静态成员,该成员在初始化后从服务中设置。但是这太不干净了,我不会把它作为答案贴出来的。。如果我用SPEL来解决它。可能吗?提前谢谢。