spring-annotations

Parameter 0 of constructor in required a bean of type 'java.lang.String' that could not be found

大兔子大兔子 提交于 2020-05-25 16:58:26
问题 I am working on spring batch with spring boot 2.X application, actually its existing code i am checked out from git. While running the application it fails due to below error only for me and same code is working for others. s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inputItemReader' defined in file [C:\Users\XYZ\git

Spring Security @PreAuthorization pass enums in directly

五迷三道 提交于 2020-05-10 07:40:10
问题 My question is a duplicate of Custom annotation with spring security but it went unanswered and I believe there should be a simple solution to the problem. Basically instead of doing: @PreAuthorize("hasPermission(T(fully.qualified.Someclass).WHATEVER, T(fully.qualified.Permission).READ") I would like to do: @PreAuthorize(Someclass.WHATEVER, Permission.READ) or possibly some custom annotation that will wire up easily with spring security This seems much cleaner to me and I would like to be

Spring custom formatter to field annotation does not work

房东的猫 提交于 2020-04-16 03:58:21
问题 I'm trying to apply formatter-annotation to the field "phone" in next model-class: public class User { @ContactNumberFormate private String phone; } Interface for annotation: @Target({ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface ContactNumberFormate { } Formatter: @Component public class PhoneFormatter implements Formatter<String> { @Override public String parse(String phoneNum, Locale locale) throws ParseException { phoneNum = phoneNum.trim();

Spring @Scheduled annotation random delay

醉酒当歌 提交于 2020-04-08 08:55:29
问题 I am using the @Scheduled annotation from Spring framework to invoke a method. But I have multiple nodes in my setup and I do not want them to all run at exactly the same time. So I'd like to set a random value to the initial delay to offset them from each other. import org.springframework.scheduling.annotation.Scheduled; @Scheduled(fixedRate = 600000, initialDelay = <random number between 0 and 10 minutes> ) Unfortunately, I am only allowed to use a constant expression here. Is there any

How can I use a custom executor for an @Async method?

自闭症网瘾萝莉.ら 提交于 2020-03-16 07:41:30
问题 I am using ThreadPoolExecutor as my custom executor with @ASync annotation. In google, I have found that the task below needs to be configured in xml but I'm not sure how the myExecutor is mapped to my custom executor. <task:annotation-driven executor="myExecutor" /> Even found that in bean properties, its path is not given. How is it called then? 回答1: Four options: Declare a single bean of type TaskExecutor Declare a single bean with the name AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR

Spring boot component scan include a single class [duplicate]

耗尽温柔 提交于 2020-02-21 10:35:46
问题 This question already has answers here : Using @ComponentScan or <context:component-scan /> with only one class (4 answers) Closed 2 years ago . I am using spring component scan to auto detect beans as: @ComponentScan({"com.org.x, com.org.y"}) The issue is I want all classes in com.org.x to be scanned but I want a single class, com.org.y.SomeService.class , alone to be scanned from com.org.y How can I achieve this ? Also apart from using context scan, how can I created this bean and inject in

Why changing the order of the joinColumn, hibernate return a correct or incorrect query?

北城余情 提交于 2020-01-24 10:51:06
问题 PROBLEM: Why changing the order of the joinColumn, hibernate return a correct or incorrect query? FIRST JOIN: @OneToOne @JoinTable(name="TTR_POA_UPA", joinColumns = { @JoinColumn(name="ANO", insertable=false, updatable=false), @JoinColumn(name="ID_ESCALA", insertable=false, updatable=false), @JoinColumn(name="MES", insertable=false, updatable=false) }, inverseJoinColumns = { @JoinColumn(name="ANO", insertable=false, updatable=false), @JoinColumn(name="ID_ESCALA", insertable=false, updatable

Spring validation @AssertTrue

爱⌒轻易说出口 提交于 2020-01-23 06:58:27
问题 How do I display on a view jsp validation error message that occurs as a result of @AssertTrue annotation? It isn't tied to a specific field, but I am using it to validate a combination of fields. If I use <form:errors path="*"/> that will display all the errors for that form? 回答1: From what I have tested it is important HOW you name your test function. And you should name it properly. You do not need field, getter or setter but your function HAVE TO start with 'is*' statement. fe.

Spring validation @AssertTrue

為{幸葍}努か 提交于 2020-01-23 06:58:24
问题 How do I display on a view jsp validation error message that occurs as a result of @AssertTrue annotation? It isn't tied to a specific field, but I am using it to validate a combination of fields. If I use <form:errors path="*"/> that will display all the errors for that form? 回答1: From what I have tested it is important HOW you name your test function. And you should name it properly. You do not need field, getter or setter but your function HAVE TO start with 'is*' statement. fe.

Spring @Value annotated method, use default value when properties not available

只愿长相守 提交于 2020-01-22 07:33:22
问题 Situation I am injecting properties from .properties file into fields annotated with @Value . However this properties present sensitive credentials, so I remove them from repository. I still want that in case someone wants to run project and doesnt have .properties file with credentials that default values will be set to fields. Problem Even if I set default values to field itself I get exception when .properties file is not present: org.springframework.beans.factory.BeanCreationException: