我不明白为什么在这里的情况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) 我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)
有人可以解释我简要地有什么用JdbcApprovalStore
用JWTTokenStore
?
我有单独的授权服务器和资源服务器。授权服务器指向一个单独的数据库。我曾经使用过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-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) HistoryRecord类:
public class DataHistoryRecord {
Long dataCreatedBy;
Long dataModifiedBy;
getters & setters
}
Run Code Online (Sandbox Code Playgroud)
我有List<DataHistoryRecord>
,我想用HashSet
它创造独特dataCreatedBy
和dataModifiedBy
id.
例如:如果列表有以下两条记录:
HistoryRecord1 with createdBy:1和modifiedBy:2
HistoryRecord2 with createdBy:1和modifiedBy:3
输出HashSet
应该有三个值; 1,2,3
注意:请建议没有foreach的方法