spring-annotations

not able to publish custom event in spring before context load

南楼画角 提交于 2021-02-07 20:00:28
问题 I am trying to publish a custom event in Spring MVC, but is is not firing while context is loading, below are the code snippet, The onConnectionOpened will be called after connecting to a server which is triggered after bean initialization using @PostConstruct @Autowired private ApplicationEventPublisher publisher; public void onConnectionOpened(EventObject event) { publisher.publishEvent(new StateEvent("ConnectionOpened", event)); } I am using annotation in listener part as below

not able to publish custom event in spring before context load

给你一囗甜甜゛ 提交于 2021-02-07 19:55:48
问题 I am trying to publish a custom event in Spring MVC, but is is not firing while context is loading, below are the code snippet, The onConnectionOpened will be called after connecting to a server which is triggered after bean initialization using @PostConstruct @Autowired private ApplicationEventPublisher publisher; public void onConnectionOpened(EventObject event) { publisher.publishEvent(new StateEvent("ConnectionOpened", event)); } I am using annotation in listener part as below

Spring MVC: Having multiple @ModelAttribute in form handling action

谁说胖子不能爱 提交于 2021-02-07 12:47:14
问题 The context I have a simple association between two entities - Category and Email (NtoM). I'm trying to create web interface for browsing and managing them. To browse the category and to add e-mails into that category I use controller wrapped with @RequestMapping with category ID (UUID), so all controller actions are always taking place in context of category specified with path. I use @ModelAttribute to pre-load context category for entire controller scope. The problem This approach worked

Maven: package io.swagger.annotations does not exist

半世苍凉 提交于 2021-02-07 12:26:23
问题 I want to document my project with swagger. I add swagger annotations and io.springfox dependencies to my project but when I run mvn clean package I have a lot of errors: PS D:\parent-project> mvn clean package [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] parent-project [pom] [INFO] module-common-lib [jar] [INFO] module1 [jar] [INFO] module2 [jar] [INFO] [INFO] ------------< parent

How to add dot to regex

江枫思渺然 提交于 2021-02-05 08:23:08
问题 @Pattern(regexp="^\\w{8,}") private String username; This pattern can only consist of numbers, letters and the underscore character. How can I add the dot (.) to the pattern Thanks 回答1: Try this, it might be easier to understand if you explicitly define all valid characters: @Pattern(regexp="^[A-Za-z0-9_.]{8,}") private String username; 回答2: You need to add end of the line anchor also. @Pattern(regexp="^[.\\w]{8,}$") 来源: https://stackoverflow.com/questions/29515276/how-to-add-dot-to-regex

Are there anyway to disable annotation in spring4?

流过昼夜 提交于 2021-02-05 04:48:37
问题 I have a question, maybe simple, but I can not find out the solution. I am using spring boot and added some annotation to the code like this: @EnableEurekaClient @SpringBootApplication @EnableCaching public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } But in some other environment, for example, in production environment, we want to remove EurekaClient, but I do not want to manually remove it manually for each environment,

Are there anyway to disable annotation in spring4?

醉酒当歌 提交于 2021-02-05 04:48:16
问题 I have a question, maybe simple, but I can not find out the solution. I am using spring boot and added some annotation to the code like this: @EnableEurekaClient @SpringBootApplication @EnableCaching public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } But in some other environment, for example, in production environment, we want to remove EurekaClient, but I do not want to manually remove it manually for each environment,

Custom annotation is not working on spring Beans

二次信任 提交于 2021-01-27 15:55:57
问题 I have created my new custom annotation @MyCustomAnnotation @Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) @Retention(RUNTIME) public @interface MyCustomAnnotation{ } I applied that annotation on component and bean. Here is the code, @MyCustomAnnotation @Component public class CoreBussinessLogicHandler implements GenericHandler<BussinessFile> { //some bussiness logic } And @Configuration public class BussinessConfig { @Autowired private CoreIntegrationComponent

Custom annotation is not working on spring Beans

拥有回忆 提交于 2021-01-27 14:55:21
问题 I have created my new custom annotation @MyCustomAnnotation @Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) @Retention(RUNTIME) public @interface MyCustomAnnotation{ } I applied that annotation on component and bean. Here is the code, @MyCustomAnnotation @Component public class CoreBussinessLogicHandler implements GenericHandler<BussinessFile> { //some bussiness logic } And @Configuration public class BussinessConfig { @Autowired private CoreIntegrationComponent

Spring @Value empty list as default

元气小坏坏 提交于 2021-01-20 15:55:52
问题 Is there a way to set an empty list as default value for a property in Spring, something like: @Value("${my.list.of.strings :" + new ArrayList<>() + "}") private List<String> myList; Obviously not new ArrayList, but I need an empty list there instead. 回答1: After taking a look at SpEL specification and combined with @javaguy's answer I came up with this: @Value("${my.list.of.strings:}#{T(java.util.Collections).emptyList()}") private List<String> myList; 回答2: Actually, in the current Spring