Приложение Spring Boot: не удалось разрешить заполнитель в application.properties? ⇐ JAVA
Приложение Spring Boot: не удалось разрешить заполнитель в application.properties?
I have a spring boot app. It works when fine when I click "run" button in SpringToolSuit4.
But when I run as "maven install", I got the error message:
java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'envVersionNum' in value "${envVersionNum}" Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'envVersionNum' in value "${envVersionNum}" The content of my application properties:
spring.h2.console.enabled=true spring.h2.console.path=/h2-console spring.jpa.show-sql=true spring.thymeleaf.cache=false version=${envVersionNum} If I change it to
spring.h2.console.enabled=true spring.h2.console.path=/h2-console spring.jpa.show-sql=true spring.thymeleaf.cache=false version=1.1.1 It works fine. But I want to get the envVersionNum from user, which is stored in .bash_profile (export envVersionNum= 1.1.1).
the content of pom.xml:
4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.1.RELEASE com.jrp project-management 0.0.1-SNAPSHOT project-management project management application 1.8 org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true com.h2database h2 runtime org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin
The code of homeController:
package com.jrp.pma.controllers; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.jrp.pma.dao.EmployeeRepository; import com.jrp.pma.dao.ProjectRepository; import com.jrp.pma.dto.ChartData; import com.jrp.pma.dto.EmployeeProject; import com.jrp.pma.entities.Project; @Controller public class HomeController { @Value("${version}") private String ver; @Autowired ProjectRepository proRepo; @Autowired EmployeeRepository empRepo; @GetMapping("/") public String displayHome(Model model) throws JsonProcessingException { model.addAttribute("versionNumber", ver); Map map = new HashMap(); // we are querying the database for projects List projects = proRepo.findAll(); model.addAttribute("projectsList", projects); List projectData = proRepo.getProjectStatus(); // Lets convert projectData object into a json structure for use in javascript ObjectMapper objectMapper = new ObjectMapper(); String jsonString = objectMapper.writeValueAsString(projectData); //[["NOTSTARTED", 1], ["INPROGRESS", 2], ["COMPLETED", 1]] model.addAttribute("projectStatusCnt", jsonString); // we are querying the database for employees List employeesProjectCnt = empRepo.employeeProjects(); model.addAttribute("employeesListProjectsCnt", employeesProjectCnt); return "main/home"; } } Any suggestions gratefully accepted.
Источник: https://stackoverflow.com/questions/592 ... properties
I have a spring boot app. It works when fine when I click "run" button in SpringToolSuit4.
But when I run as "maven install", I got the error message:
java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'envVersionNum' in value "${envVersionNum}" Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'envVersionNum' in value "${envVersionNum}" The content of my application properties:
spring.h2.console.enabled=true spring.h2.console.path=/h2-console spring.jpa.show-sql=true spring.thymeleaf.cache=false version=${envVersionNum} If I change it to
spring.h2.console.enabled=true spring.h2.console.path=/h2-console spring.jpa.show-sql=true spring.thymeleaf.cache=false version=1.1.1 It works fine. But I want to get the envVersionNum from user, which is stored in .bash_profile (export envVersionNum= 1.1.1).
the content of pom.xml:
4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.1.RELEASE com.jrp project-management 0.0.1-SNAPSHOT project-management project management application 1.8 org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true com.h2database h2 runtime org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin
The code of homeController:
package com.jrp.pma.controllers; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.jrp.pma.dao.EmployeeRepository; import com.jrp.pma.dao.ProjectRepository; import com.jrp.pma.dto.ChartData; import com.jrp.pma.dto.EmployeeProject; import com.jrp.pma.entities.Project; @Controller public class HomeController { @Value("${version}") private String ver; @Autowired ProjectRepository proRepo; @Autowired EmployeeRepository empRepo; @GetMapping("/") public String displayHome(Model model) throws JsonProcessingException { model.addAttribute("versionNumber", ver); Map map = new HashMap(); // we are querying the database for projects List projects = proRepo.findAll(); model.addAttribute("projectsList", projects); List projectData = proRepo.getProjectStatus(); // Lets convert projectData object into a json structure for use in javascript ObjectMapper objectMapper = new ObjectMapper(); String jsonString = objectMapper.writeValueAsString(projectData); //[["NOTSTARTED", 1], ["INPROGRESS", 2], ["COMPLETED", 1]] model.addAttribute("projectStatusCnt", jsonString); // we are querying the database for employees List employeesProjectCnt = empRepo.employeeProjects(); model.addAttribute("employeesListProjectsCnt", employeesProjectCnt); return "main/home"; } } Any suggestions gratefully accepted.
Источник: https://stackoverflow.com/questions/592 ... properties
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как преобразовать application.properties в application.yml в Spring Boot?
Anonymous » » в форуме JAVA - 0 Ответы
- 59 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как преобразовать application.properties в application.yml в Spring Boot?
Anonymous » » в форуме JAVA - 0 Ответы
- 30 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как преобразовать application.properties в application.yml в Spring Boot?
Anonymous » » в форуме JAVA - 0 Ответы
- 30 Просмотры
-
Последнее сообщение Anonymous
-