spring-boot

Why does Spring Boot discover but not instantiate a @Component?

蓝咒 提交于 2021-02-18 22:55:36
问题 I have a Spring Boot application with the following structure com.package Application - annotated with @SpringBootApplication Configuration - annotated with @Configuration Component1 - annotated with @Component, constructor annotated with @Autowired com.package.subpackage Component2 - annotated with @Component, constructor annotated with @Autowired My application class is package com.package; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure

How can I start spring boot application in docker with profile?

旧时模样 提交于 2021-02-18 22:43:31
问题 I have a simple spring-boot project: -resources -application.yaml -application-test.yaml And I have this Dockerfile : FROM openjdk:8-jdk-alpine EXPOSE 8080 ADD micro-boot.jar micro-boot.jar ENTRYPOINT ["java","-Dspring.profiles.active=test" "-jar","/micro-boot.jar"] 1) I build image - C:\micro-boot>docker build -f Dockerfile -t micro-boot . 2) show all images - C:\micro-boot>docker image ls -a micro-boot latest ccc9a75ebc24 4 seconds ago 112MB 3) try to start C:\micro-boot>docker image ls -a

What's the best way to load a yaml file to Map(not an environment configuration file) in spring boot web project?

本小妞迷上赌 提交于 2021-02-18 22:30:28
问题 In my data framework layer, I'd like to read an yaml from src/main/resources . The file name is mapconfigure.yaml . It's associated with the business data, not just environment configuration data. Its content's like: person1: name: aaa addresses: na: jiang sb: su person2: name: bbb addresses: to: jiang bit: su I want to store this information into a HashMap. Does it mean to use some spring annotation like @ConfigurationProperties ? How to achieve this in details? In addition, I can't change

What's the best way to load a yaml file to Map(not an environment configuration file) in spring boot web project?

笑着哭i 提交于 2021-02-18 22:29:45
问题 In my data framework layer, I'd like to read an yaml from src/main/resources . The file name is mapconfigure.yaml . It's associated with the business data, not just environment configuration data. Its content's like: person1: name: aaa addresses: na: jiang sb: su person2: name: bbb addresses: to: jiang bit: su I want to store this information into a HashMap. Does it mean to use some spring annotation like @ConfigurationProperties ? How to achieve this in details? In addition, I can't change

Spring boot thymeleaf images

半城伤御伤魂 提交于 2021-02-18 21:14:00
问题 I'm trying to develop spring boot application for sendind emails. All is ok But in the template thymeleaf, when I try to add images it display error. This is a snippet of my template.html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title th:remove="all">Order Confirmation</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <div> <h2 th:text="${title}">title</h2> <p th:utext="${description}"> description </p> <br /> <br /> <br />

Spring boot thymeleaf images

被刻印的时光 ゝ 提交于 2021-02-18 21:13:27
问题 I'm trying to develop spring boot application for sendind emails. All is ok But in the template thymeleaf, when I try to add images it display error. This is a snippet of my template.html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title th:remove="all">Order Confirmation</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <div> <h2 th:text="${title}">title</h2> <p th:utext="${description}"> description </p> <br /> <br /> <br />

Spring @Validated annotation prevents @ConfigurationProproperties value injection, why?

五迷三道 提交于 2021-02-18 19:32:57
问题 I am trying with @ConfigurationProperties and I find two things: for tests to work, I have to put configuration properties files (yml) in test package; setters and an empty constructor are required. If I annotated the class with @Validated , injection just fails with all null values. If you say the first one is understandable, and the second one? Why? The purpose is to validate configuration properties injection, so that crucial properties values should not be absent when the application

Spring @Validated annotation prevents @ConfigurationProproperties value injection, why?

半腔热情 提交于 2021-02-18 19:31:10
问题 I am trying with @ConfigurationProperties and I find two things: for tests to work, I have to put configuration properties files (yml) in test package; setters and an empty constructor are required. If I annotated the class with @Validated , injection just fails with all null values. If you say the first one is understandable, and the second one? Why? The purpose is to validate configuration properties injection, so that crucial properties values should not be absent when the application

Java Spring Boot - spring-boot-starter-tomcat dependency doesn't work with scope provided when running locally

做~自己de王妃 提交于 2021-02-18 19:03:08
问题 I'm developing a Java Spring Boot application that needs to run on our client's Tomcat server. This application basically contains a REST API that serves files to our frontend. Running this application locally went great until our first deployment testing on the client's servers. We had to refactor our code and add some dependencies to the projects' pom.xml. This eventually worked (kind of). Now I wanted to again start developing locally and noticed my code wasn't able to run with the same

Register Caffeine Cache in Spring Actuator (CacheManager)

一曲冷凌霜 提交于 2021-02-18 19:00:23
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache