spring-mvc

How to filter attributes from JSON response in spring?

十年热恋 提交于 2021-02-08 10:03:38
问题 I have a controller like the following, @RequestMapping(value = "rest/v1/tester") public class TestController { @RequestMapping(value = "/search", method = RequestMethod.GET) public ResponseEntity<SampleResults> search(@ModelAttribute("criteria")SampleCriteria criteria) throws Exception { SampleResults sampleResults = sampleService.search(criteria); return new ResponseEntity<>(sampleResults, OK); } } I have another controller like so, @RequestMapping(value = "rest/v1/second") public class

How to handle session creation and adding hidden input csrf token for any page containing a form for an anonymous user in Spring Boot?

我只是一个虾纸丫 提交于 2021-02-08 09:58:10
问题 I Introduce the problem: when I launch the application and I enter the url "/home". The home page is displayed but not correctly (the template is not well organized) and I receive an exception TemplateInputException . After a while, If I refresh the home page and the other pages It comes back to normal but if I go to "/login", and I logout which redirects me to the home view the same issue comes back again. The Stacktrace Console: org.thymeleaf.exceptions.TemplateInputException: An error

Deploying Multiple Spring Boot Web Applications in Single Server

て烟熏妆下的殇ゞ 提交于 2021-02-08 09:43:13
问题 I have 5 Spring Boot web applications but have only one Server (low-end). What is the best way to deploy all 5 in one Server? Having only one web container (Tomcat) and deploy all of them as separate war files on the same Tomcat or run all 5 on different Tomcat containers (Spring Boot default behavior)? What is your recommendation by considering performance and maintenanability? 回答1: IMHO, if you're running a resource-constrained server, your best bet is to deploy all of your applications as

Deploying Multiple Spring Boot Web Applications in Single Server

血红的双手。 提交于 2021-02-08 09:42:15
问题 I have 5 Spring Boot web applications but have only one Server (low-end). What is the best way to deploy all 5 in one Server? Having only one web container (Tomcat) and deploy all of them as separate war files on the same Tomcat or run all 5 on different Tomcat containers (Spring Boot default behavior)? What is your recommendation by considering performance and maintenanability? 回答1: IMHO, if you're running a resource-constrained server, your best bet is to deploy all of your applications as

Mixing entity with payload (dto) in spring boot - best practice

二次信任 提交于 2021-02-08 09:23:34
问题 Is it good practice to have one class being both entity (mapped and stored in the database) and payload (object serialized and returned form REST endpoint) at the same time? I heard somewhere that entities should never go higher than service layer but rather should be mapped to DTO objects in services and then these DTO should be returned to controllers. I personally think this is bad practice because in such class we mix annotations for serializing to JSON and for mapping object to the

Mixing entity with payload (dto) in spring boot - best practice

一笑奈何 提交于 2021-02-08 09:23:23
问题 Is it good practice to have one class being both entity (mapped and stored in the database) and payload (object serialized and returned form REST endpoint) at the same time? I heard somewhere that entities should never go higher than service layer but rather should be mapped to DTO objects in services and then these DTO should be returned to controllers. I personally think this is bad practice because in such class we mix annotations for serializing to JSON and for mapping object to the

Reading multiple properties files with @PropertySource (SpringBoot)using wildcard character

可紊 提交于 2021-02-08 09:22:17
问题 I want to read multiples properties files from a specific location, say C:\config . I'm taking help of @PropertySource annotation. Is there a way to read these files in Springboot using some wildcard character e.g (*.properties). So what I intended to achieve is something like this @PropertySource("*.properties") }) public class SomeClass{ } If not, Is there a way to create these @PropertySource("foo.properties") or @PropertySource("bar.properties") programmatically and provide them to

How to restrict routes in spring security dynamically?

半城伤御伤魂 提交于 2021-02-08 08:57:18
问题 Good day, I am using spring security to restrict user, and i am using mongodb. I have created UserDetail and userDetail Services. her is my webSecurity config. @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public UserDetailsService mongoUserDetails() { return new CustomUserDetailsService(); } @Bean public DaoAuthenticationProvider authProvider() { DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V

走远了吗. 提交于 2021-02-08 08:33:28
问题 I am getting this run-time error: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V And part of stack trace: Caused By: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.j ava:915) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:575) at

Read Spring boot property inside listener

末鹿安然 提交于 2021-02-08 04:39:45
问题 My requirement is, I need to initialize some application resources when server is started in spring boot. In order to initialize those resources, I need bunch of properties. So, I have kept those properties in external property file and I am trying to read the properties in my custom listener when spring boot is started. The problem is, I could not get any property values in the listener. I am able to read them after application started without any issues. But, I need them inside listener