Questions tagged [spring-annotations]
A common placeholder for issues related to the use of annotations with the Spring framework
1,211
questions
1
vote
1
answer
48
views
@Value not Injecting ANY value
I'm learning how to create a RESTful API with Springboot, and the @Value tag is not injecting values from application.properties, nor is it injecting values specified in the tag itself. I have my ...
0
votes
0
answers
20
views
Java - Not able to get value of Custom Annotation using Reflection
I'm trying to generate a report and the fields should be in the specified sequence. As this is microservices architecture, I've a db service where interface based projection is used. On top of it, I'm ...
0
votes
0
answers
19
views
@Qualifier on the custom annotation
I was just going through this below video on proxy mechanism.
refer time : 17:45 to 18:30
I also started reading about annotations and reflection recently. So Incase you would prefer to understand the ...
0
votes
0
answers
23
views
Alternative for using @Nullable for double in Java Spring Boot?
I've made a class for request body, now it has a double field which might come in request body sometimes and sometimes it won't, how should I handle it? Sample code:
@Nullable
private String ...
0
votes
1
answer
48
views
how to solve feign.RetryableException: connect timed out executing
error image feign-client error test enviroment
The code work correctly in localhost connection.
In test enviroment don't work.
I have microservices that run in the cloud.
I tried to add in the ...
0
votes
1
answer
29
views
MongoDB create compund index text and NumberLong with spring-boot annotation
please look this mongodb index:
{
"v" : 2,
"key" : {
"_fts" : "text",
"_ftsx" : 1,
"time_in_millisecond" : -...
0
votes
0
answers
10
views
MessageMapping in WebSockets Spring is not being called even though stomp sent is working
Message Mapping Controller
@Controller
public class MessageControl {
@MessageMapping("/message")
@SendTo("/topic/return")
public Message getContent(Message message) {
...
0
votes
1
answer
43
views
Custom annotation for field value
I need to write a custom annotation that can act as a validator.
I have a field called name that need to match [a-zA-z0-9_@]. If not I need to raise an error.
I read this custom annotation
article. In ...
0
votes
1
answer
44
views
Creating reusable REST resource for Java Spring
Let's say I have an entity called Book for a very simple RESTful app created within the Java Spring framework, i.e. I have the Book model/entity (which maps the data to/from the books table in a db). ...
2
votes
3
answers
120
views
How do I use a configuration class to configure properties for my application in Spring Boot?
I am trying my hand at using a Spring Configuration class to set up configuration for my project. I created a new trial project for I did not want to edit my original project (Sorry for all this crap, ...
0
votes
1
answer
30
views
Spring Boot 2.x.x - Combine 2 conditions in @ConditionalOnProperty
I have the following interface :
@Primary
@ConditionalOnProperty(value = "ms.couchbase.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(value = "...
0
votes
0
answers
18
views
Spring framework abstraction for creating beans from interfaces
Is there an abstraction for creating spring beans from interfaces like JpaRepositoriesRegistrar does in spring-data-jpa using RepositoryBeanDefinitionRegistrarSupport from spring-data-commons?
0
votes
0
answers
38
views
Pass value from properties to @Column annotation
Helo, Is it possible to pass value from application.properties to @Column annotation in entity?
I tried this:
@Column(name = "${foo.column-name}")
private String foo;
and this:
@Formula(...
0
votes
2
answers
164
views
My custom validation annotation is not working in Spring Boot
i have created an annotation that has features such as checking if the entered string is null or at the assigned value.But the annotation doesn't work. I don't think it does any validation on the DTO....
0
votes
0
answers
41
views
Auto generated String type @Id in Spring Boot to connect mongo
I am incrementing my Autogenerated Id value but I need String type
.This is my service class:
package com.stackroute.orderhistory.service;
import com.stackroute.orderhistory.model.AutogenerateId;
...
0
votes
0
answers
30
views
how to use variable in spring annotation?
You are using the Pageable object provided by Spring, and you need to display this object through swagger. I am using Custom Annotation.
I want to change the size value of @ApiImplicitParam according ...
0
votes
0
answers
21
views
java costom annotation to accept request body
I am trying for a custom annotation that when applied to a controller would log all the parameters by default.
but I'm facing issues when I'm trying to read the body as the stream is getting closed ...
0
votes
0
answers
19
views
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'
Getting Error when I am trying to enable annotations
Here is the code
0
votes
0
answers
49
views
Invalid XML '<Contacts>'. Error: unexpected element (uri:"", local:"Contacts"). Expected elements are (none)
I am new to the relationships and workings behind XMLs, XSDs, XSLs and the marshaling and unmarshaling processes that come with them. I am working on a web app where the user can upload an XML file in ...
0
votes
0
answers
20
views
Converting alternate keys from HBM XML file to Java Annotations - Hibernate
I am trying to upgrade some legacy code, going from Hibernate 3 to Hibernate 5.
The old code heavily relied on HBM XML files. And it has this tag: <properties>
I couldn't find anything online on ...
0
votes
1
answer
81
views
Not getting values from application.properties in SpringBoot application
I created a simple SpringBoot application using "http://start.spring.io" Spring Initializr. I am using JDK 8 and Spring 2.6.6.
I opened an application in IntelliJ and was able to build it ...
2
votes
2
answers
346
views
How to process custom annotation in Spring Boot with Kotlin?
CONTEXT:
I would like to create a custom annotation in Spring Boot and add extra logic for processing. I give an example with rather simplistic annotation but I want to have several of such ...
0
votes
0
answers
48
views
Spring custom annotation validate http header with reflection
I have an endpoint secured with token given in the header. I would like to create my custom annotation so when I annotate the controller method the validation token goes first and then if the token ...
0
votes
0
answers
110
views
Java Spring custom annotation reflection
I have an endpoint secured with a token given in the header. I would like to create my custom annotation so when I annotate the controller method the validation for the token goes first and then if ...
1
vote
1
answer
64
views
@NotNull annotation doesn't throw exception
I have a problem. I want to throw an exception when an attribute is null, but the @NotNull annotation doesn't seem to be working. I use Spring 2.6.4
My controller:
@RestController
public class ...
0
votes
0
answers
10
views
Spring Validating requests params
I want to add validation annotations to my requests params in a Spring annotation. I have the required javax dependencies and code looks something like this
@RestController
public class Controller {
...
0
votes
0
answers
26
views
Spring Async Annotation: Executor Id by Enum
I have a custom @Async annotation with the specified Executor ID.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Async("fixedThreadPool")
public @...
0
votes
0
answers
19
views
Where is the implementation part of @Query in spring jpa?
I want to rewrite @Query in spring jpa, want to add additional condition like 'active=ture'
for instance my selection is:
select u from student u
I want to use my defined @Query like @MyQuery ...
0
votes
1
answer
53
views
How to know which kafka is being consumed from list?
I have a function for consuming Kafka. I consume multiple topics in the same function. But I don't know which topic is consumed
@KafkaListener(topics = {"topic1","topic2"})
...
-1
votes
2
answers
429
views
Difference between @Entity and @Table in Spring boot . Do we need both?
Do we need both annonation for a model class? What is the difference between @Entity and @Table
@Entity
@Table(name = "widget") // do we need this??
public class WidgetEntity {
@Id
@...
0
votes
0
answers
17
views
Alias annotation for providing value to bean method parameter in another annotation
I've been looking around the forum for solution that would implement this functionality, but couldn't find any I could understand. Is it possible to create an alias or through creating an processor an ...
0
votes
0
answers
27
views
RequestParam Validation
Please How to validate list of items with requestparam annotation in spring boot.
in my case I want to validate the barber items input
the controller :
@PostMapping("/barber")
public Barber ...
1
vote
1
answer
78
views
spring 5 How do I send a parameter with a .json suffix in the @pathvariable
I have a service that receives "long" as a parameter type, but sending the parameter with the .json suffix does not resolve it and I take it as if it were a "string" . For example, ...
1
vote
1
answer
56
views
Spring @Value FileNotFound when running on azure pipeline
In my spring project I have a unit test like this:
@ExtendWith(SpringExtension.class)
@WebMvcTest(BuildingController.class)
class BuildingControllerTest {
@Value("classpath:building/...
0
votes
1
answer
57
views
How to run relevant methods using annotation?
Maybe this question title is not up to my queries but I am searching for the answers for so long.
After adding Lombok to a project, we can use getter, setter, Slf4j, etc. Like
@Getter
@Setter
public ...
1
vote
1
answer
241
views
Why to use @Autowired to run Kafka Streams topology in a Spring Boot Application?
I am trying to run Kafka Streams Topology inside a spring boot application.
In the example on confluent website they did the following:
@Component
class Processor {
@Autowired
public void ...
1
vote
0
answers
135
views
Unable to retrieve value from Config Server using @Value annotation in Spring Boot
I have been trying to retrieve an attribute value from Config Server which has an application.properties file saves on GitHub repository. The property is defined in the application.properties file is ...
0
votes
1
answer
90
views
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter doesn't have the setAlwaysUseFullPath method
I am migrating from spring 4 to spring 5. In spring 4, org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter is deprecated in favor of RequestMappingHandlerAdapter. However, ...
2
votes
1
answer
34
views
Why is basePackageClasses (@ComponentScan) "Type-Safe"?
Can someone help with meaning of Type-Safety in this context?
I'm somehow not very clear with the understanding of the Javadoc -
https://docs.spring.io/spring-framework/docs/3.1.4.RELEASE/javadoc-api/...
1
vote
0
answers
112
views
Alias for repeatable Swagger/OpeanAPI meta-annotation
I have a REST controller, in which each method is bearing Swagger's @ApiResponseannotation for multiple response codes. In case of an HTTP 200 response code the schema implementation differs for each ...
0
votes
1
answer
866
views
NoSuchBeanDefinitionException : No bean available in Spring
I am facing a very trivial error and cant figure out why. I have created a simple Student class and a MyConfig class for implementing Spring annotation based configuration. I tried using @Bean & @...
0
votes
2
answers
61
views
How to make form input and the value table be on the same page with Spring MVC and Thymleaf?
I want to insert a set of values and display a list of inserted data on the same page. What should I do in the controller class?
Here are all my codes
UserController.java
package com.crud.controll;
...
0
votes
1
answer
52
views
Spring Annotation: replacing @ControllerAdvice
I'm tasked with removing functionality given by @ControllerAdvice(basePackages = {"com.bla.controller"}) located in an old applications. This functionality became outdated, creating some ...
0
votes
1
answer
671
views
springdoc swagger ui not showing entity component model schema
org.springdoc-openapi-ui version = 1.5.13 using Maven 4.0.0, java 11
model user.java
@Entity(name = "User")
@Table(name = "User")
public class User {
@Id
@GeneratedValue(...
1
vote
0
answers
56
views
Spring - @Configuration - AnnotationConfigApplicationContext - problem on server
I tried several solutions. I´ve read a lot on Internet. I did not find a correct answer.
I will explain :
This is my configuration file :
@Configuration
@PropertySource("file:src/property/config....
1
vote
1
answer
90
views
How to express array annotation argument in Kotlin?
When annotation has an array argument with basic type like String or Int it is straightforward how to use that:
public @interface MyAnnotation{
String[] props();
}
@MyAnnotation(props = ["A&...
0
votes
0
answers
116
views
How to Create annotations which can declare variable using class name from its usage
following
public class Testclass {
private static final LogExtension log = new LogExtension(Testclass.class);
}
should work with just:
@LogExtension
public class Testclass{}
similar to @Slf4j ...
0
votes
2
answers
139
views
How to create datasource bean at runtime without crashing app in Spring?
I am connecting to multiple datasources but sometimes some datasources may be offline and at that time I am geting errors on app and application is failing at startup.
I want to skip datasource ...
0
votes
1
answer
204
views
Import a .properties file into a java.util.Properties type variable in Configuration class via annotation
I am migrating my java application from spring to spring boot and along with it I want to eradicate the xml based configuration and move to annotation based configuration completely.
I want to load a ...
0
votes
2
answers
111
views
Can @Transactional method call another @Transactional method without suspending?
I have method A and method B in different classes. Both are annotated with @Transactional. Method A is calling B. Is there any solution to call B in different transaction but without suspending A ...