spring-boot

Getting Ambiguous @ExceptionHandler method mapped for MethodArgumentNotValidException while startup of spring boot application

懵懂的女人 提交于 2021-02-16 15:52:32
问题 I have written custom exception handler class for one of my spring controllers to validate if email attribute from request param is in the proper format. So created a new class which extends ResponseEntityExceptionHandler class and wrote a method with @ExceptionHandler . But during spring boot application startup, I am getting below exception which is stopping to run my project. Could someone help me to resolve this? Exception during server startup: org.springframework.beans.factory

Create spring repository without entity

限于喜欢 提交于 2021-02-16 15:47:14
问题 I want to use spring data repository interface to execute native queries - I think this way is the simplest because of low complexity. But when extending interface ex. CrudRepository<T, ID> I need to write T - my entity, which is not available. My native queries does not return any concrete entity, so what is the best way to create spring repository without entity? 回答1: CrudRepository or JpaRepository were not designed to work without an <Entity,ID> pair. You are better off creating a custom

Environment Variables in spring-boot application.properties error

99封情书 提交于 2021-02-16 15:32:08
问题 I have been looking at this answer to reference environment variables in spring boot application.properties. However, when I do this an error is returned saying they cannot resolve $(MYAPP_MYSQL_DB_USERNAME} Application.properties spring.datasource.username = ${MYAPP_MYSQL_DB_USERNAME} Error org.dbunit.dataset.DataSetException: java.sql.SQLException: Access denied for user '${MYAPP_MYSQL_DB_USERNAME}'@'localhost' (using password: YES) at org.dbunit.database.DatabaseDataSet.initialize

How to isolate spring boot app redis and spring boot session global redis

ぃ、小莉子 提交于 2021-02-16 15:28:05
问题 As I know, spring boot and spring session provided us one-stop autoconfig, but when my app use session redis and app cache redis not same redis server; How can I config it, thank you very much for your reply! 回答1: Indeed, by default, both spring-session and spring-cache are actually configured by spring-boot with a RedisConnectionFactory bean named as connectionFactory . Two ways to do this. make spring-session to use a different connectionFactory bean instance, and leave spring-cache to use

How to isolate spring boot app redis and spring boot session global redis

别说谁变了你拦得住时间么 提交于 2021-02-16 15:27:27
问题 As I know, spring boot and spring session provided us one-stop autoconfig, but when my app use session redis and app cache redis not same redis server; How can I config it, thank you very much for your reply! 回答1: Indeed, by default, both spring-session and spring-cache are actually configured by spring-boot with a RedisConnectionFactory bean named as connectionFactory . Two ways to do this. make spring-session to use a different connectionFactory bean instance, and leave spring-cache to use

Send two Serialized Java objects under one Kafka Topic

浪子不回头ぞ 提交于 2021-02-16 15:26:04
问题 I want to implement Kafka Consumer and Producer which sends and receives Java Objects. Full Source I tried this: Producer: @Configuration public class KafkaProducerConfig { @Value(value = "${kafka.bootstrapAddress}") private String bootstrapAddress; @Bean public ProducerFactory<String, SaleRequestFactory> saleRequestFactoryProducerFactory() { Map<String, Object> configProps = new HashMap<>(); configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress); configProps.put

Send two Serialized Java objects under one Kafka Topic

杀马特。学长 韩版系。学妹 提交于 2021-02-16 15:26:01
问题 I want to implement Kafka Consumer and Producer which sends and receives Java Objects. Full Source I tried this: Producer: @Configuration public class KafkaProducerConfig { @Value(value = "${kafka.bootstrapAddress}") private String bootstrapAddress; @Bean public ProducerFactory<String, SaleRequestFactory> saleRequestFactoryProducerFactory() { Map<String, Object> configProps = new HashMap<>(); configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress); configProps.put

Why my Springboot with embbeded tomcat too slow when process first request?

半腔热情 提交于 2021-02-16 14:08:26
问题 Env. OS:macOS Mojave Version 10.14.5(centOS have same problem) Springboot:2.1.6.RELEASE(embedded tomcat 9.0.21),war My native language is not english,please forgive my poor english。 I am a new player of SpringBoot, which I think is helpful to build my project. Now I have finish my work with it,But a strange phenomenon harass me. My project cost about 5 minutes to response first request, it cost 5 minutes not 5 seconds, the request after first sames normally。It was extraordinary slow, So I

Why my Springboot with embbeded tomcat too slow when process first request?

你离开我真会死。 提交于 2021-02-16 14:05:41
问题 Env. OS:macOS Mojave Version 10.14.5(centOS have same problem) Springboot:2.1.6.RELEASE(embedded tomcat 9.0.21),war My native language is not english,please forgive my poor english。 I am a new player of SpringBoot, which I think is helpful to build my project. Now I have finish my work with it,But a strange phenomenon harass me. My project cost about 5 minutes to response first request, it cost 5 minutes not 5 seconds, the request after first sames normally。It was extraordinary slow, So I

@Timed annotation in spring metrics

一世执手 提交于 2021-02-16 13:08:36
问题 I use @Timed annotation on String Boot rest controller and it works fine. Method from controller calls method from service which is also annotated with @Timed . However, this annotation on method in subsequent service bean doesn't work (I don't see results in /metrics ). Why is it happening? Could it be fixed? 回答1: As per Support for @Timed in any Spring-managed bean #361 you can get this behaviour by registering TimedAspect manually. @Configuration @EnableAspectJAutoProxy public class