小编027*_*027的帖子

使用原始类型和包装类的varargs重载时为什么会出现模糊错误?

我不明白为什么在这里的情况1,它没有给出编译错误,相反在情况2(varargs),它给出了编译错误.任何人都可以详细说明编译器在这两种情况下的差异吗?我经历过很多关于它的帖子,但还不能理解它.

情况1

public class Test {

    public void display(int a) {
        System.out.println("1");
    }

    public void display(Integer a) {
        System.out.println("2");
    }

    public static void main(String[] args) {
        new Test().display(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

输出为: 1

案例#2

public class Test {

    public void display(int... a) {
        System.out.println("1");
    }

    public void display(Integer... a) {
        System.out.println("2");
    }

    public static void main(String[] args) {
        new Test().display(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

编译错误:

The method display(int[]) is ambiguous for the type Test
Run Code Online (Sandbox Code Playgroud)

java primitive overloading variadic-functions wrapper

7
推荐指数
1
解决办法
481
查看次数

spring-security-oauth中JdbcApprovalStore(ApprovalStore)的用途是什么?

JWTTOkenStore在spring-security-oauth中使用。

我面临的问题是我想添加撤销JWT令牌的支持。我知道还有其他选项可以解决此问题,但我正在寻找此选项。我发现我们可以使用org.springframework.security.oauth2.provider.approval.JdbcApprovalStore相同的。我的理解正确吗?我确实在互联网上搜索了一些示例,但没有找到任何示例。

    /**
     * ApprovalStore to be used to validate and restrict refresh tokens.
     * 
     * @param approvalStore the approvalStore to set
     */
    public void setApprovalStore(ApprovalStore approvalStore) {
        this.approvalStore = approvalStore;
    }
Run Code Online (Sandbox Code Playgroud)

有人可以解释我简要地有什么用JdbcApprovalStoreJWTTokenStore

java spring-security jwt spring-security-oauth2

6
推荐指数
1
解决办法
793
查看次数

如何在spring-security-oauth2中的资源服务器中获取自定义UserDetailService对象?

我有单独的授权服务器和资源服务器。授权服务器指向一个单独的数据库。我曾经使用过CustomUserDetailService与用户相关的信息。CustomTokenEnhancer除了响应中的令牌外,我过去常常有其他信息。

@Configuration
public class OAuth2Configuration {


    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter implements EnvironmentAware {

        private static final String ENV_OAUTH = "authentication.oauth.";
        private static final String PROP_CLIENTID = "clientid";
        private static final String PROP_SECRET = "secret";
        private static final String PROP_TOKEN_VALIDITY_SECONDS = "tokenValidityInSeconds";

        private RelaxedPropertyResolver propertyResolver;

        @Autowired
        private DataSource dataSource;

        @Autowired
        private CustomUserDetailService userDetailsService;

        @Bean
        public TokenStore tokenStore() {
            return new CustomTokenStore(dataSource);
        }

        @Autowired
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws …
Run Code Online (Sandbox Code Playgroud)

spring-security-oauth2

5
推荐指数
1
解决办法
2789
查看次数

每当在spring-security-oauth中插入新的访问令牌时如何执行一些代码?

我使用spring-security-oauth实现了Oauth2.我使用了密码和刷新令牌授权类型.

流程是用户首先显示用户名和密码,验证后,授权服务器提供刷新令牌.使用该刷新令牌,我获得了可用于访问受保护资源的访问令牌.

@Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter implements EnvironmentAware {

        private static final String ENV_OAUTH = "authentication.oauth.";
        private static final String PROP_CLIENTID = "clientid";
        private static final String PROP_SECRET = "secret";
        private static final String PROP_TOKEN_VALIDITY_SECONDS = "tokenValidityInSeconds";

        private RelaxedPropertyResolver propertyResolver;

        @Autowired
        private DataSource dataSource;

        @Bean
        public TokenStore tokenStore() {
            return new JdbcTokenStore(dataSource);
        }

        @Autowired
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {
            endpoints
                    .tokenStore(tokenStore())
                    .authenticationManager(authenticationManager);
        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-security-oauth2

2
推荐指数
1
解决办法
137
查看次数

如何使用Java8 Stream从对象中获取多个字段值,从List <Object>创建HashSet?

HistoryRecord类:

public class DataHistoryRecord {

Long dataCreatedBy;
Long dataModifiedBy;
getters & setters

}
Run Code Online (Sandbox Code Playgroud)

我有List<DataHistoryRecord>,我想用HashSet它创造独特dataCreatedBydataModifiedByid.

例如:如果列表有以下两条记录:

HistoryRecord1 with createdBy:1和modifiedBy:2

HistoryRecord2 with createdBy:1和modifiedBy:3

输出HashSet应该有三个值; 1,2,3

注意:请建议没有foreach的方法

java java-8 java-stream

2
推荐指数
1
解决办法
118
查看次数