Tag: 春季启动

当返回1xx状态码时,Spring引导请求挂起

我有一个小的演示来玩定制的状态码。 有趣的部分是,如果状态低于200,请求将始终挂在那里,如105,199等。但对于任何超过200的状态,如209,789等 http状态码注册表,请参考https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Spring引导:1.5.4.RELEASE与嵌入式的tomcat Java:8 控制器: @RestController public class DemoController { @GetMapping("/hello") public ResponseEntity get() { return ResponseEntity.status(105).build(); } } 任何人都可以给我一个明确的解释? 我在这里创建一个要点: https : //gist.github.com/pengisgood/dbea1fcdc45c2bb5809871c7f020b800 更新: 我也创建一个小的演示来重现它在这里: https : //github.com/pengisgood/springboot-customize-status-code 更新: 运行curl -v localhost:8080/hello ,可以看到状态,但是响应没有完成。 参考下面的gif:

使用Spring MVC和Boot刷新静态内容

我正在评估Spring MVC&Boot和AngularJs构建Web应用程序。 我遇到了问题,当我修改我的静态内容(html,js,css)时,我不得不每次重新启动应用程序。 我希望有一个解决方法,因为重新启动整个应用程序的静态内容变化效率不高。 我试过的每个其他Web应用程序框架允许更新静态内容文件(即使只是Spring MVC和普通的旧WAR应用程序)。 我已经从“使用Spring Boot Actuator构建REST风格的Web服务”指南( http://spring.io/guides/gs/actuator-service/ )安装我的项目。 基本上它使用Spring Boot和MVC控制器来创建一个REST服务。 另外,我使用了“使用AngularJS使用REST风格的Web服务”( http://spring.io/guides/gs/consuming-rest-angularjs/ )来构建AngularJS的前端。 它创建一个显示REST服务响应的网页。 我做的唯一的改变是请求是由我的应用程序而不是“ http://rest-service.guides.spring.io/greeting ”。 我的静态内容存储在“src / main / resources / public”文件夹中。 除非不重新加载静态内容,否则此设置可以正常工作。

如何用Spring WebFlux返回404

我有一个这样的控制器(在Kotlin中): @RestController @RequestMapping("/") class CustomerController (private val service: CustomerService) { @GetMapping("/{id}") fun findById(@PathVariable id: String, @RequestHeader(value = IF_NONE_MATCH) versionHeader: String?): Mono<HttpEntity<KundeResource>> = return service.findById(id) .switchIfEmpty(Mono.error(NotFoundException())) .map { // ETag stuff … ok().eTag("…").body(…) } } 我想知道是否有一个更好的方法比抛出一个异常是用@ResponseStatus(code = NOT_FOUND)注解@ResponseStatus(code = NOT_FOUND)

遇到多个对数据库序列的引用

构建JHipster应用程序时出现此错误: org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]中定义名称为'entityManagerFactory'的bean时出错:init方法的调用失败; 嵌套的异常是org.hibernate.HibernateException:遇到数据库序列[hibernate_sequence]的多个引用尝试toset冲突值为'增量大小'。 发现[1]和[50] 我在这里看到50,但是我不知道1是从哪里来的。 自从最后一次工作以来,我在这些 Kotlin文件中添加了一些新的实体。 我正在将Thinkter管道演示作为一项功能添加到我的应用程序中。 自行演示构建和运行没有任何问题。 为了得到我现在所在的位置,我将演示中的代码复制到了我的应用程序中,并调整了一些与用户实体相关的内容。 由于JHipster不允许您向用户添加字段,因此我创建了一个与其1:1关系的Author实体。 这本身可能与这个错误没有任何关系。 我认为这个新代码中的某些东西必须尝试创建一个序列,并且默认的增量大小是1。

春季启动不等待请求

昨天我得到了非常奇怪的春季开机行为 例如:我试图启动服务器使用./gradlew bootRun : … :findMainClass :bootRun :: Spring Boot :: (v1.3.1.RELEASE) 2016-01-19 16:37:15.315 INFO 6118 — [ main] ceserver.Application$Companion : Starting Application.Companion on fake with PID 6118 (/home/user/code/xproject/server/build/classes/main started by user in /home/user/code/xproject/server) 2016-01-19 16:37:15.320 INFO 6118 — [ main] ceserver.Application$Companion : No active profile set, falling back to default profiles: default 2016-01-19 16:37:15.400 […]

Spring Boot Controller语言环境不随参数更改

我在使用Kotlin的Spring Boot来处理区域设置时遇到了一些麻烦。 我在我的application.properties文件中创建了这些设置: spring.messages.basename=messages/messages spring.messages.cache-seconds=-1 spring.messages.encoding=UTF-8 然后在我的控制器中创建一个MessageSource的自动装配实例: @Autowired lateinit var messageSource: MessageSource 当把url中的语言环境作为参数时,当我调用LocaleContextHolder.getLocale()时,这个参数似乎没有被拾取,所以它总是en_US。 虽然,我可以使用@RequestParam(value="locale") locale: Locale作为我的控制器函数的一个参数手动提取,并在控制器函数中使用它,但不能在其他函数中使用它。 我认为,春季启动LocaleContextHolder应该保持当前的区域设置基于请求的URL自动为整个会话。 我读了一篇较老的文章,提到在主类中使用LocaleChangeInterceptor bean以及MessageSource和LocaleResolver的bean,但另一篇文章则说Spring Boot并不需要这样做。 无论如何,我尝试了没有区别。 这些是我使用的功能: @Bean open fun localeResolver(): LocaleResolver { val slr = SessionLocaleResolver() slr.setDefaultLocale(Locale.US) return slr } @Bean open fun localeChangeInterceptor(): LocaleChangeInterceptor { val localeChangeInterceptor = LocaleChangeInterceptor() localeChangeInterceptor.paramName = "locale" return localeChangeInterceptor } @Bean open fun […]

ReactiveCrudRespository永远不会从SaveAll返回

在启动时,我检查一些数据,如果不存在尝试保存一些默认值(暂时用于测试)。 val subs = repo.findAll().toIterable() if(subs.none()) { repo.saveAll(defaults.map { Source(it.link.hashCode().toLong(), it::class.java.canonicalName, arrayOf(it.link)) }).blockLast() } 在第一次运行时,我们将达到saveAll(),但从不解锁。 数据保存在MongoDB中,我可以用Robo 3t来确认。 随后运行的数据实际存在将导致第一次findAll从不解锁。 在MongoDB中的分析似乎显示出一个成功的查询。 findAll()查询的配置文件 我的资源库和实体如下: interface SourceRepository : ReactiveCrudRepository<Source, Long> { // } data class Source( @Id val id: Long, val type: String, val params: Array<String> ) 这是在Kotlin,反对Spring Boot 2.0.0.M4。 我的目标是在Docker中运行的MongoDB实例。 如果我删除了这一点的启动逻辑,我的另一个ReactiveCrudRepository能够读/写就好,永远不会阻塞。 工作仓库的saveAll()调用也在blockLast()中结束,因为我发现没有这个保存就不会实际发生。

HTTP标头不在EC2上返回

我在2个EC2实例(分段和生产环境)上部署了一个Spring Boot应用程序。 我有一个用于下载文件的端点。 它看起来像这样(应用程序是用Kotlin编写的): @PostMapping("/download") open fun download(@RequestBody request: DownloadRequest, servletResponse: HttpServletResponse) { val file = getByteArray(request.fileId) servletResponse.outputStream.write(file) servletResponse.contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE servletResponse.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"${request.fileId}.zip\"") } 当我在登台机器上执行下载请求时,一切都很好。 我找回文件,响应中设置了标题。 这些是我可以在邮差看到的标题: Cache-Control →no-cache, no-store, max-age=0, must-revalidate Connection →keep-alive Content-Disposition →attachment; filename="345412.zip" Content-Length →11756 Content-Type →application/octet-stream Date →Tue, 04 Apr 2017 09:04:19 GMT Expires →0 Pragma →no-cache X-Application-Context →application:8081 […]

BadCredentialsException:GAE上的Spring引导安全性Oauth2无法获取访问令牌

我目前正在开发一个弹簧引导的小型Web应用程序。 我想使用谷歌oauth2登录我的用户。 所有的工作就像在我的电脑本地主机的魅力,但是当我在GAE部署我的应用程序,我得到一个错误。 这是我从GAE上的开发服务器得到的错误堆栈。 我猜这个错误在生产模式下是一样的。 [INFO] 2017-08-27 17:02:31.290 DEBUG 630 — [tp1134612201-18] gcAuthorizationCodeAccessTokenProvider : Retrieving token from https://www.googleapis.com/oauth2/v4/token [INFO] 2017-08-27 17:02:31.565 DEBUG 630 — [tp1134612201-18] osweb.client.RestTemplate : Created POST request for "https://www.googleapis.com/oauth2/v4/token" [INFO] 2017-08-27 17:02:31.566 DEBUG 630 — [tp1134612201-18] gcAuthorizationCodeAccessTokenProvider : Encoding and sending form: {grant_type=[authorization_code], code=[4/PmvPPmFGQF0PamafaItFDiqKT_RwZN4RkdoydpxOTD4], redirect_uri=[https://127.0.0.1:8080/login], client_id=[XXX], client_secret=[YYY]} [INFO] 2017-08-27 17:02:32.905 DEBUG 630 […]

Spring启动REST服务:JSON反序列化不起作用

我正在使用spring-boot和Kotlin开发一个REST服务。 (我应该提到这是我第一次同时使用)。我无法让杰克逊使用此代码从POST请求反序列化JSON: @RequestMapping("cloudservice/login/{uuid}", method = arrayOf(RequestMethod.POST)) fun login(@PathVariable(value="uuid")uuid: String, @RequestBody user: CloudServiceUser ) : ResponseEntity<CloudServiceUser> { val cloudServiceFactory : Class<CloudServiceFactory> = cloudServiceRepository.cloudServiceExtensions[UUID.fromString(uuid)] ?: throw InvalidPathVariableException("Invalid UUID.") var token : String try { token = cloudServiceFactory.newInstance().authenticationService.login(user.userId, user.password) } catch (e:Exception ){ throw CloudServiceException(e.message) } return ResponseEntity(CloudServiceUser(userId=user.userId, password = "", token = token),HttpStatus.OK) } 用户对象很简单: data class […]