小编Jes*_*nen的帖子

Spring Boot REST API - 请求超时?

我有一个Spring Boot REST服务,有时会将第三方服务作为请求的一部分.我想在我的所有资源上设置一个超时(让我们说5秒),这样如果任何请求处理(整个链,从传入到响应)花费的时间超过5秒,我的控制器会响应HTTP 503而不是实际响应.如果这只是一个Spring属性,例如设置,那将是非常棒的

spring.mvc.async.request-timeout=5000
Run Code Online (Sandbox Code Playgroud)

但我没有运气.我也尝试过扩展WebMvcConfigurationSupport并覆盖configureAsyncSupport:

@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
    configurer.setDefaultTimeout(5000);
    configurer.registerCallableInterceptors(timeoutInterceptor());
}

@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
    return new TimeoutCallableProcessingInterceptor();
}
Run Code Online (Sandbox Code Playgroud)

没有运气.

我怀疑我必须手动计算所有第三方呼叫的时间,如果它们花费的时间太长,则抛出超时异常.是对的吗?或者是否有涵盖我所有请求端点的更简单,整体的解决方案?

java rest spring timeout spring-boot

19
推荐指数
6
解决办法
6万
查看次数

在刷新令牌上找不到AuthenticationProvider - Spring OAuth2 java config

我有一个Spring Boot项目,我在其中配置了一个部分有效的Spring OAuth2身份验证过程.我可以验证确定,但是当我尝试获取刷新令牌时,我得到一个例外.

OAuth配置:

@Configuration
public class OAuth2ServerConfiguration {

    private static final String RESOURCE_ID = "xxx";

    @Configuration
    @EnableResourceServer
    protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) {
            resources.resourceId(RESOURCE_ID);
        }

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http
            .authorizeRequests()
            .antMatchers("/api/**").authenticated();
        }
    }

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {

        @Value("${clientDetailsService.clientName}")
        private String clientName;

        @Value("${clientDetailsService.clientSecret}")
        private String clientSecret;

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

        @Autowired
        private ClientDetailsService clientDetailsService;

        @Autowired
        @Qualifier("tokenServices")
        private AuthorizationServerTokenServices tokenServices;

        @Autowired
        @Qualifier("codeServices")
        private …
Run Code Online (Sandbox Code Playgroud)

java authentication spring oauth spring-boot

5
推荐指数
2
解决办法
4618
查看次数

SSLHandshakeException:收到致命警报:在Java 6 - > 8升级后的handshake_failure

我们最近更新了一个从Java 6到Java 8的项目,现在我们已经打了一个关于SSL握手的问题.

服务层使用客户端来请求和接收来自第三方应用程序的呼叫.在服务层中,使用初始化密钥库

    System.setProperty("javax.net.ssl.trustStore", keyStoreFile);
    System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);
Run Code Online (Sandbox Code Playgroud)

并通过applicationContext.xml注入:

    <property name="keyStoreFile" value="/keystore/keystore.keystore" />
    <property name="keyStorePassword" value="password" />
Run Code Online (Sandbox Code Playgroud)

奇怪的是:1.显然,这不是一个完整的文件路径.2.此服务器上没有密钥库(无论Java 6如何都可以使用).

如果出现错误,客户端应该信任所有证书:

/**
 * Sets a trust manager that ignores the certificate chains. Use if the 
 * server has a certificate that can't be verified.
 * 
 */
private void trustHttpsCertificates() throws Exception {

    try {
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

        // Create a trust manager that does not validate certificate chains 
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return …
Run Code Online (Sandbox Code Playgroud)

java ssl https keystore

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

Spring Boot - 不覆盖服务器端口属性

我有一个Spring Boot项目,无论server.port属性如何,服务器端口总是设置为8080.除server.port之外的所有属性都会被正确覆盖.属性配置bean:

@Bean
public PropertySourcesPlaceholderConfigurer properties() {
    final PropertySourcesPlaceholderConfigurer poc = new PropertySourcesPlaceholderConfigurer();
    poc.setIgnoreResourceNotFound(true);
    poc.setIgnoreUnresolvablePlaceholders(true);

    final List<Resource> list = new ArrayList<Resource>();

    // default (dev) properties
    list.add(new ClassPathResource(PROPERTIES_FILE));

    // override with -Dproperties.location=C:/path/to/properties/ where overriding application.properties resides
    list.add(new FileSystemResource(System.getProperty(EXTERNAL_ARGUMENT_NAME)+PROPERTIES_FILE));

    poc.setLocations(list.toArray(new Resource[]{}));

    return poc;
}
Run Code Online (Sandbox Code Playgroud)

这意味着我的classpath application.properties是默认的(dev属性),它被jvm参数-Dproperties.location = C:\ application\config覆盖.

server.port属性未在我的类路径属性文件中定义,因此在开发环境中默认为8080.这很好,但是为了测试我想指定端口.我的外部属性文件包含以下属性:

server.port=10070
Run Code Online (Sandbox Code Playgroud)

日志:

[2016-01-19 11:14:10:010 CET]  INFO [restartedMain] support.PropertySourcesPlaceholderConfigurer: Loading properties file from class path resource [application.properties]
[2016-01-19 11:14:10:010 CET]  INFO [restartedMain] support.PropertySourcesPlaceholderConfigurer: Loading properties file from file [C:\var\opt\application\config\application.properties]
[2016-01-19 11:14:11:011 CET]  INFO …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat properties spring-boot

4
推荐指数
1
解决办法
4513
查看次数