spring-boot

Forbid Unauthenticated requests in Spring Cloud Gateway

三世轮回 提交于 2021-02-08 16:37:34
问题 I have implemented custom pre filter in spring cloud gateway which allows authenticated requests to go through the downstream process. What I want is if the request is unauthenticated then return with response of 401 UNAUTHORIZE status and stop the downstream processing. Can I achieve this spring cloud gateway. Please help. My filter code is below public class ValidUserFilter implements GatewayFilterFactory { @Override public GatewayFilter apply(Object config) { return (exchange, chain) -> {

Storing emojis in MySQL database

别说谁变了你拦得住时间么 提交于 2021-02-08 15:07:41
问题 I'm using Spring boot and I can't store emojis in database. I don't have access to my.cnf file. What I've done so far is: ALTER DATABASE name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; For each table: ALTER TABLE table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; For each column: ALTER TABLE table CHANGE column column VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; In application.properties file I'm using this: spring.datasource.url = jdbc:mysql:/

Storing emojis in MySQL database

旧街凉风 提交于 2021-02-08 15:05:18
问题 I'm using Spring boot and I can't store emojis in database. I don't have access to my.cnf file. What I've done so far is: ALTER DATABASE name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; For each table: ALTER TABLE table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; For each column: ALTER TABLE table CHANGE column column VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; In application.properties file I'm using this: spring.datasource.url = jdbc:mysql:/

@IfProfileValue not working with JUnit 5 SpringExtension

大城市里の小女人 提交于 2021-02-08 13:19:38
问题 I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith . However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class) , below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) class MyApplicationTests{ @Test @DisplayName("Application Context should be loaded") @IfProfileValue(name = "test-groups" , value="unit-test") void contextLoads() { } } so the contextLoads should be

@IfProfileValue not working with JUnit 5 SpringExtension

Deadly 提交于 2021-02-08 13:19:31
问题 I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith . However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class) , below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) class MyApplicationTests{ @Test @DisplayName("Application Context should be loaded") @IfProfileValue(name = "test-groups" , value="unit-test") void contextLoads() { } } so the contextLoads should be

Datatable: date / time sorting plug-in not ordering

跟風遠走 提交于 2021-02-08 13:11:06
问题 I have a basic SpringBoot app., embedded Tomcat, Thymeleaf template engine I want to order 1 date column of a datatable. in my POJO: public String getTimeFormatted() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d,yyyy h:mm,a", Locale.ENGLISH); LocalDateTime dateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.UTC); return dateTime.format(formatter); } in the template: <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>

Datatable: date / time sorting plug-in not ordering

喜你入骨 提交于 2021-02-08 13:10:51
问题 I have a basic SpringBoot app., embedded Tomcat, Thymeleaf template engine I want to order 1 date column of a datatable. in my POJO: public String getTimeFormatted() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d,yyyy h:mm,a", Locale.ENGLISH); LocalDateTime dateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.UTC); return dateTime.format(formatter); } in the template: <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>

Issue with CORS and error and Access-Control-Allow-Origin header

社会主义新天地 提交于 2021-02-08 12:38:09
问题 Hi I cant disable CORS in my project. I use a custom filter and Spring Security Config for the CORS configuration. I have seen this excellent answer: Can you completely disable CORS support in Spring? but when I have tried the below implementation I still get the CORS error: CORS configuration: @Component @Order(Ordered.HIGHEST_PRECEDENCE) class CorsFilter @Autowired constructor() : CorsFilter(configSrc()) { companion object { private fun configSrc(): UrlBasedCorsConfigurationSource { val

Configuring base package for component scan in Spring boot test

人盡茶涼 提交于 2021-02-08 12:20:01
问题 When I launch my test with the following annotations: package com.hello.package.p1; @RunWith(SpringRunner.class) @DataMongoTest @SpringBootTest public class ClassATest { @Autowired Service1 serivce1; //fqn = com.hello.package.p1.Service1 @Autowired Service2 serivce2; //fqn = com.hello.package.p2.Service2 ...} package com.hello.package.p1; @ActiveProfiles("test") @SpringBootConfiguration public class MongoTestConfig { ... } service1 will be injected. But service2 will not, since it is not in

Catching & Handling Jackson Exceptions with a custom message

♀尐吖头ヾ 提交于 2021-02-08 12:19:57
问题 I'm hoping to to catch some jackson exceptions that are occurring in a spring-boot API I am developing. For example, I have the following request class and I want to catch the error that occurs when the "questionnaireResponse" key in the JSON request object is null or blank i.e " " in the request object. @Validated @JsonRootName("questionnaireResponse") public class QuestionnaireResponse { @JsonProperty("identifier") @Valid private Identifier identifier = null; @JsonProperty("basedOn") @Valid