Spring

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

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

Replacing the default filter at position SESSION_MANAGEMENT_FILTER

大憨熊 提交于 2021-02-16 15:14:08
问题 I want to replace the default SessionManagementFilter with my own, but I'm running into this 17:31:32,901 ERROR [[/accounts]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Filter beans '<accountsSessionManageFilter>' and 'Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=;

How to test a spring mvc controller

爱⌒轻易说出口 提交于 2021-02-16 15:07:45
问题 I have the following controller: @Controller public class HomeController { @Resource(name="returnGraph") Graph returnGraph; @RequestMapping("/") public String goToHomePage(HttpSession session){ session.setAttribute("sm", returnGraph.getVertexes()); return "home"; } } I tried the following j unit test but it didnt work: public class HomeControllerTest { @Mock Graph returnGraph; @Mock Map<String,Vertex> vertexes; @Mock HttpSession session; HomeController homeController; @Before public void

How to upload file in spring?

与世无争的帅哥 提交于 2021-02-16 14:59:41
问题 I am not able to get the file name in spring controller <form:form method="post" modelAttribute="sampleDetails" enctype="multipart/form-data"> <input type="file" name="uploadedFileName" id="fileToUpload" required="" > <input type="submit" name="import_file" value="Import File" id="" /> </form:form> Its my post method in controller @RequestMapping(method = RequestMethod.POST) public String importQuestion(@Valid @RequestParam("uploadedFileName") MultipartFile multipart, @ModelAttribute(

Size limit with spring MVC POST form?

柔情痞子 提交于 2021-02-16 14:26:09
问题 I have a form : <form:form modelAttribute="zgImport" action="${importAfterValidationUsers}" method="POST" name="ImportForm" > in which I display csv content (one line per user). My controller method get the object : public void importAfterValidationUsers(@ModelAttribute ("zgImport") ZgImport zgImport, ActionRequest request, ActionResponse response) { Problem is : if I have many lines (more than 670) the object "zgImport" that I get in my controller is not fully filed, I miss some data. Is

@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