spring-boot

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

SSL settings spring boot

岁酱吖の 提交于 2021-02-08 09:22:29
问题 I have some questions about ssl in spring boot. I have files certifications and private key with extension .crt and .key. how can I get from them right format for settings in spring boot like this server.ssl.key-store-type=PKCS12 server.ssl.key-store=classpath:keystore.p12 server.ssl.key-store-password=password server.ssl.key-alias=tomcat 回答1: To convert a certificate file and private key to PKCS#12(.p12) format, use the below command: openssl pkcs12 -export -out certificate.p12 -inkey

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

Spring JPA Datasource Crash Recovery and Dynamic Changes on runtime

徘徊边缘 提交于 2021-02-08 09:15:36
问题 Hi I use spring jpa and as I understand its working mechanism truely it created at once in a singleton way. Is it possible to change or recreate datasource on running environment.Scenario like this,Mypassword changed and if I wont stop application that time all my calls take exception.I have a mechanism to check password and change it dynamically and my others request get new password create new datasource and keep on working. And another question is I have multiple datasource,at the

Spring JPA Datasource Crash Recovery and Dynamic Changes on runtime

こ雲淡風輕ζ 提交于 2021-02-08 09:04:04
问题 Hi I use spring jpa and as I understand its working mechanism truely it created at once in a singleton way. Is it possible to change or recreate datasource on running environment.Scenario like this,Mypassword changed and if I wont stop application that time all my calls take exception.I have a mechanism to check password and change it dynamically and my others request get new password create new datasource and keep on working. And another question is I have multiple datasource,at the

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();

How to use @CachePut and @CacheEvict on the same method in a Spring Boot application?

醉酒当歌 提交于 2021-02-08 08:56:50
问题 I'm working on a Spring Boot application where I have a scenario to put @CachePut and @CacheEvict on the same method. I tried the scenario with this code given below : @CachePut(value="myValue",key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching") @CacheEvict(value="myValue", key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching", condition="#entity.isDeleted() == true") public MyEntity save(boolean flag, MyEntity entity){ if (flag==true){ entity

How to use @CachePut and @CacheEvict on the same method in a Spring Boot application?

情到浓时终转凉″ 提交于 2021-02-08 08:56:30
问题 I'm working on a Spring Boot application where I have a scenario to put @CachePut and @CacheEvict on the same method. I tried the scenario with this code given below : @CachePut(value="myValue",key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching") @CacheEvict(value="myValue", key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching", condition="#entity.isDeleted() == true") public MyEntity save(boolean flag, MyEntity entity){ if (flag==true){ entity

Hibernate Annotation relations does not work with spring.jpa.generate-ddl=true

走远了吗. 提交于 2021-02-08 08:55:23
问题 I am creating some simple Spring Boot project with Hibernate JPA. I created some data model which consists 5 tables for now and created entities reflecting tables. I have set spring.jpa.generate-ddl=true and my entities was correctly reflected by schema created in PostgreSQL. Next step was to start adding relations. Part of my assumed datamodel is (paron my UML) Very simple one to many relation. My entities look that way (getters and setters omitted below, exist in code): @Entity public class