小编Mun*_*del的帖子

如何在spring boot中更改logback版本?

我想在我的spring启动应用程序中使用logback smtp appender,但不知何故,spring boot默认的logback 1.1.7依赖关系不适用于SMTP appender.如何将spring boot提供的logback库从1.1.7降级到1.1.6?我正在使用gradle进行构建管理.

更新

它在我尝试了Andy的答案之后起作用,所以现在我的build.gradle文件看起来像这样

buildscript {
...    
 ext['logback.version'] = '1.1.6'
 ...
}
Run Code Online (Sandbox Code Playgroud)

java gradle spring-boot

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

在 API 网关级别与在单个微服务级别解码 OAuth2 JWT

我使用 Spring Boot 1.5.x + OAuth2 和 JWT 开发了一组微服务(资源服务器)。现在每个微服务都使用 Spring Security 进行保护,即 JWT 访问令牌在单个资源服务器级别进行验证。API Gateway 没有适当的 spring 安全性,因此它只是将请求路由到适当的服务器并将身份验证标头传播到下游服务。

我想知道与仅在 API 网关级别验证 AccessToken 的设置相比,此设置是否有任何缺点。或者这只是一个意见问题?在 API 网关级别保持安全性是否违反了松散耦合的原则,因为每个微服务可能会更好地理解给定用户在其自身上下文中的角色?

spring-boot spring-security-oauth2 microservices

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

给定范围内的随机服务器端口spring boot

我想在给定范围 (5001-5100) 的随机端口上启动 Spring Cloud 应用程序(Spring Boot 1.5.14,Spring Cloud Edgware.SR4)。我知道我们可以使用在 Spring Boot 应用程序中指定随机端口server.port=0,但我面临以下两个问题:

  1. 选择给定范围内的动态可用端口 [5000-5100]
  2. Eureka 注册表在我使用时显示端口为 0 server.port=0,spring cloud 是否支持动态端口?

spring-boot

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

更改默认URL映射以在Spring Boot中提供静态内容

当我使用以下映射在应用程序中添加新控制器(非休息)后,我的静态资源就停止工作

@RequestMapping(value = "/{postId}/{postUri:.+}", method = RequestMethod.GET)
public String viewPost(@ModelAttribute("model") ModelMap model, PathVariable("postId") String postId, PathVariable("postUri") String postUri) {
          // do something
}
Run Code Online (Sandbox Code Playgroud)

调试之后,我发现我新添加的控制器方法开始拾取静态资源,基本上,它优先于静态资源的默认映射。

例如,对以下静态资源的请求到达了我的控制器,而不是静态资源处理程序。

http://localhost:7999/css/bootstrap-2a31dca112f26923b51676cb764c58d5.css
Run Code Online (Sandbox Code Playgroud)

我正在使用Spring Boot 1.4

因为我不想修改Controller方法的URL,是否可以修改用于提供默认静态内容的映射URL?

web-deployment spring-boot

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

将Spring Boot从1.5.12迁移到1.5.13后,ehcache提供错误

我已经配置了Spring Boot 1.5.12 + ehcache,一切正常,直到我将Spring Boot升级到1.5.13

application.yml 具有以下条目

spring:
  cache:
    jcache:
      provider: org.ehcache.jsr107.EhcacheCachingProvider
      config: ehcache.xml
Run Code Online (Sandbox Code Playgroud)

ehcache.xml位于resources目录下

我收到的错误是:

Caused by: java.lang.IllegalArgumentException: Cache configuration does not exist 'ServletContext resource [/ehcache.xml]'
    at org.springframework.util.Assert.isTrue(Assert.java:92)
    at org.springframework.boot.autoconfigure.cache.CacheProperties.resolveConfigLocation(CacheProperties.java:117)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.createCacheManager(JCacheCacheConfiguration.java:113)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.jCacheCacheManager(JCacheCacheConfiguration.java:97)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047.CGLIB$jCacheCacheManager$1(<generated>)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047$$FastClassBySpringCGLIB$$a6ae7187.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047.jCacheCacheManager(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 47 common frames omitted
Run Code Online (Sandbox Code Playgroud)

看来Spring Boot已开始搜索ehcache.xml使用ServletContext解析器。

ps:除了将Spring Boot升级到1.5.13之外,我没有任何源代码更改

我在这里缺少一些必需的配置吗?

spring-boot spring-cache

3
推荐指数
1
解决办法
692
查看次数

asciidoctorj 库不适用于 Spring Boot 2 可执行引导 jar

我试图在 Spring Boot 2.0.3 中使用 asciidoctorj,当我从 IntelliJ IDEA 运行项目时一切正常,但是当我创建一个引导 jar 时,我开始看到以下错误:

Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- asciidoctor
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:956) ~[jruby-complete-9.1.16.0.jar!/:na]
    at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55) ~[na:na]
    at RUBY.<main>(<script>:15) ~[na:na]
Run Code Online (Sandbox Code Playgroud)

这是来自 build.gradle 的片段

buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

... committed few lines

springBoot {
    buildInfo()
}

bootJar {
    launchScript()
    mainClassName = "com.example.demo.DemoApplication"
    requiresUnpack 'org.jruby:jruby-complete', 'org.asciidoctor:asciidoctorj'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.asciidoctor:asciidoctorj:1.5.7')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

我的项目托管在,如果有人想看看它

https://github.com/cancerian0684/spring-boot2-asciidoctorj

用于使用 Spring Boot …

spring-boot asciidoctor gradle-plugin

3
推荐指数
1
解决办法
541
查看次数