spring-mvc

Spring service implementation by environment property

不羁岁月 提交于 2021-01-22 21:14:26
问题 I have a service interface interface ImageSearchService { // methods... } And I have 2 implementations: @Service class GoogleImageSearchImpl implements ImageSearchService { // methods... } @Service class AzureImageSearchImpl implements ImageSearchService { // methods... } And I have a controller to use one of the both: @Controller ImageSearchController { @Autowired ImageSearchService imageSearch; // Google or Azure ?!? } How can I use a Environment API to set the right one implementation? If

Error occuring template parsing. (Spring Boot + Thymeleaf)

心已入冬 提交于 2021-01-22 05:14:36
问题 I have a Spring Boot for serving images. My Model is included in my ImageController.java. ImageService contains findPage method. When running my Spring Boot Application I am getting this error. 2018-06-21 15:09:14.777 ERROR 26828 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]") org.thymeleaf.exceptions

Error occuring template parsing. (Spring Boot + Thymeleaf)

Deadly 提交于 2021-01-22 05:11:14
问题 I have a Spring Boot for serving images. My Model is included in my ImageController.java. ImageService contains findPage method. When running my Spring Boot Application I am getting this error. 2018-06-21 15:09:14.777 ERROR 26828 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]") org.thymeleaf.exceptions

Error occuring template parsing. (Spring Boot + Thymeleaf)

徘徊边缘 提交于 2021-01-22 05:08:06
问题 I have a Spring Boot for serving images. My Model is included in my ImageController.java. ImageService contains findPage method. When running my Spring Boot Application I am getting this error. 2018-06-21 15:09:14.777 ERROR 26828 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]") org.thymeleaf.exceptions

Spring Boot custom ErrorAttributes http status not set to response

南笙酒味 提交于 2021-01-21 11:00:54
问题 Following Spring Boot documentation I defined my own ErrorAttributes bean (see below), I was able to make the json response to show the information I wanted, including my own error code and message by using a custom exception to wrap that information and generate the error response from it. The only issue with this is that the http status of the response is not matching the one I define in the status attribute, it is not been overridden. @Bean public ErrorAttributes errorAttributes() { return

Spring Boot custom ErrorAttributes http status not set to response

萝らか妹 提交于 2021-01-21 10:59:14
问题 Following Spring Boot documentation I defined my own ErrorAttributes bean (see below), I was able to make the json response to show the information I wanted, including my own error code and message by using a custom exception to wrap that information and generate the error response from it. The only issue with this is that the http status of the response is not matching the one I define in the status attribute, it is not been overridden. @Bean public ErrorAttributes errorAttributes() { return

How to access a PathVariable of a controller specified at class level in Spring?

邮差的信 提交于 2021-01-21 07:26:13
问题 Can I do something like this with Spring MVC ? @RequestMapping(value = "/{root}") public abstract class MyBaseController { @PathVariable(value = "root") protected ThreadLocal<String> root; } @Controller public class MyController extends MyBaseController { @RequestMapping(value = "/sayHello") @ResponseBody public String hello() { return "Hello to " + this.root.get(); } } When I request to http://..../roberto/sayHello , I get this as response: Hello to roberto 回答1: You can have a path variable

How to access a PathVariable of a controller specified at class level in Spring?

人走茶凉 提交于 2021-01-21 07:26:06
问题 Can I do something like this with Spring MVC ? @RequestMapping(value = "/{root}") public abstract class MyBaseController { @PathVariable(value = "root") protected ThreadLocal<String> root; } @Controller public class MyController extends MyBaseController { @RequestMapping(value = "/sayHello") @ResponseBody public String hello() { return "Hello to " + this.root.get(); } } When I request to http://..../roberto/sayHello , I get this as response: Hello to roberto 回答1: You can have a path variable

Priority of Various Sources in PropertySources

无人久伴 提交于 2021-01-21 04:17:24
问题 Spring has introduced a new annotation @PropertySources for all classes marked as @Configuration since 4.0 . It takes different @PropertySource as argument. @PropertySources({ @PropertySource("classpath:application.properties"), @PropertySource("file:/tmp/application.properties")}) What I am interested is knowing is the ordering in case of conflict in values for the same key present in multiple properties file. I have not seen any documentation related to this that specifies an ordering. I

Could JSP file not found be a bug in spring

廉价感情. 提交于 2021-01-20 11:40:19
问题 I have followed the official files and package structure of spring boot in my application. But I am still getting a whitelabel page error. Most of the answers and suggestions dont solve this problem. Could this be a bug in spring boot? Below is how I have put my codes and the structure of how files and folders are arranged. Application.java @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } Controller