Skip to main content
Filter by
Sorted by
Tagged with
497 votes
27 answers
986k views

What are the best practices for using Java's @Override annotation and why? It seems like it would be overkill to mark every single overridden method with the @Override annotation. Are there ...
Alex B's user avatar
  • 25k
2645 votes
30 answers
1.2m views

Can @Component, @Repository, and @Service annotations be used interchangeably in Spring or do they provide any particular functionality besides acting as a notation device? In other words, if I have a ...
Colin McCree's user avatar
  • 26.5k
1401 votes
26 answers
467k views

I'm looking to make my code more readable as well as use tooling like IDE code inspection and/or static code analysis (FindBugs and Sonar) to avoid NullPointerExceptions. Many of the tools seem ...
jaxzin's user avatar
  • 14.4k
95 votes
6 answers
134k views

I would like to associate sample size values with points on a plot. I can use geom_text to position the numbers near the points, but this is messy. It would be much cleaner to line them up along the ...
jslefche's user avatar
  • 4,649
302 votes
12 answers
238k views

How do I search the whole classpath for an annotated class? I'm doing a library and I want to allow the users to annotate their classes, so when the Web application starts I need to scan the whole ...
Alotor's user avatar
  • 7,487
286 votes
8 answers
206k views

If I have a @Transactional annotation on a private method in a Spring bean, does the annotation have any effect? If the @Transactional annotation is on a public method, it works and opens a ...
Juha Syrjälä's user avatar
724 votes
15 answers
357k views

I'm learning Spring 3 and I don't seem to grasp the functionality behind <context:annotation-config> and <context:component-scan>. From what I've read they seem to handle different ...
user938214097's user avatar
600 votes
19 answers
286k views

Should you place the @Transactional in the DAO classes and/or their methods or is it better to annotate the Service classes that are using the DAO objects? Or does it make sense to annotate both ...
Thomas Einwaller's user avatar
751 votes
17 answers
515k views

I understand that @Component annotation was introduced in Spring 2.5 to get rid of XML bean definition by using classpath scanning. @Bean was introduced in spring 3.0 and can be used with @...
user1396576's user avatar
  • 7,641
305 votes
25 answers
326k views

I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing with JUnit. My bean dependencies are currently injected by using the @Autowired annotation on ...
teabot's user avatar
  • 15.5k
195 votes
6 answers
271k views

I am thinking this may not be possible in Java because annotation and its parameters are resolved at compile time. I have an interface as follows, public interface FieldValues { String[] FIELD1 = ...
Kannan Ekanath's user avatar
156 votes
22 answers
134k views

This question is somewhat related to Hibernate Annotation Placement Question. But I want to know which is better? Access via properties or access via fields? What are the advantages and disadvantages ...
Martin OConnor's user avatar
117 votes
12 answers
169k views

I have very simple persistance.xml file: <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/...
Michał Mech's user avatar
  • 2,055
459 votes
10 answers
503k views

I have a user object that is sent to and from the server. When I send out the user object, I don't want to send the hashed password to the client. So, I added @JsonIgnore on the password property, but ...
chubbsondubs's user avatar
  • 39.4k
164 votes
5 answers
428k views

Can someone explain the @RequestBody and @ResponseBody annotations in Spring 3? What are they for? Any examples would be great.
leo's user avatar
  • 3,055
251 votes
8 answers
103k views

I don't understand why there is no inheritance in Java annotations, just as Java classes. I think it would be very useful. For example: I want to know if a given annotation is a validator. With ...
sinuhepop's user avatar
  • 20.4k
532 votes
8 answers
411k views

What is the main difference between @Before and @BeforeClass and in JUnit 5 @BeforeEach and @BeforeAll @After and @AfterClass According to the JUnit Api @Before is used in the following case: When ...
Evgenij Reznik's user avatar
123 votes
2 answers
72k views

I'm using a Dependency Injection framework (Guice's AOP to intercept some method calls specifically). My class implements an interface and I would like to annotate the interface methods so the ...
Boris Pavlović's user avatar
454 votes
11 answers
305k views

Which annotation, @Resource (jsr250) or @Autowired (Spring-specific) should I use in DI? I have successfully used both in the past, @Resource(name="blah") and @Autowired @Qualifier("blah") My ...
mlo55's user avatar
  • 7,005
136 votes
16 answers
84k views

In a few large projects i have been working on lately it seems to become increasingly important to choose one or the other (XML or Annotation). As projects grow, consistency is very important for ...
abarax's user avatar
  • 6,309
118 votes
9 answers
218k views

How can I inject values into a Map from the properties file using the @Value annotation in Spring? My Spring Java class is and I tried using the $, but got the following error message: Could not ...
yathirigan's user avatar
  • 6,149
62 votes
3 answers
88k views

In my application, I had a servlet which was defined like this in the web.xml: <servlet> <display-name>Notification Servlet</display-name> <servlet-name>...
Dvora's user avatar
  • 1,183
9 votes
1 answer
6k views

Often people ask AspectJ questions like this one, so I want to answer it in a place I can easily link to later. I have this marker annotation: package de.scrum_master.app; import java.lang....
kriegaex's user avatar
  • 68.5k
34 votes
3 answers
65k views

I want to provide annotations with some values generated by some methods. I tried this so far: public @interface MyInterface { String aString(); } @MyInterface(aString = MyClass....
thelost's user avatar
  • 6,704
394 votes
8 answers
486k views

Java has the transient keyword. Why does JPA have @Transient instead of simply using the already existing java keyword?
deamon's user avatar
  • 93.1k
136 votes
10 answers
229k views

this is my code: @Column(columnName="firstname") private String firstName; @Column(columnName="lastname") private String lastName; public String getFirstName() { return ...
BeeS's user avatar
  • 1,369
311 votes
20 answers
590k views

Is it possible to set a default value for columns in JPA, and if, how is it done using annotations?
homaxto's user avatar
  • 5,798
237 votes
13 answers
115k views

What are the major areas that we can use Annotations? Is the feature a replacement for XML based configuration?
Biju CD's user avatar
  • 5,129
143 votes
11 answers
331k views

Straight to the point, problem is saving the object Operator into MySQL DB. Prior to save, I try to select from this table and it works, so is connection to db. Here is my Operator object: @Entity ...
trivunm's user avatar
  • 1,683
63 votes
10 answers
64k views

When there is nothing to implement in the marker interfaces like Serializable What is the use of implementing it?
GuruKulki's user avatar
  • 26.6k
505 votes
15 answers
250k views

Should a method that implements an interface method be annotated with @Override? The javadoc of the Override annotation says: Indicates that a method declaration is intended to override a method ...
Benno Richters's user avatar
39 votes
1 answer
8k views

I would like to know what is the use case of @NamedArg annotation in JavaFX 8 The javadoc does not give us more details, Javadoc : Annotation that provides information about argument's name. And no ...
izakiel's user avatar
  • 427
481 votes
14 answers
501k views

I am getting the following error when trying to get a JSON request and process it: org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.myweb....
Lucky Murari's user avatar
  • 12.8k
311 votes
4 answers
145k views

Today I wanted to create my first annotation interface following this documentation and I got this compiler error Invalid type for annotation member": public @interface MyAnnotation { Object ...
Daniel Rikowski's user avatar
198 votes
4 answers
65k views

I met lombok today. I'm very anxious to know how it works. A Java Geek Article gives some clues but it's not perfectly clear to me: Java 6 removes apt and make javac able to manage annotations, ...
uuidcode's user avatar
  • 3,980
86 votes
4 answers
85k views

Is it possible to add an annotation to an object (in my case in particular, a Method) at runtime? For a bit more explanation: I have two modules, moduleA and moduleB. moduleB depends upon moduleA, ...
Clayton's user avatar
  • 2,007
215 votes
5 answers
78k views

Can anyone explain in a clear way the practical differences between the java.lang.annotation.RetentionPolicy constants SOURCE, CLASS, and RUNTIME? I'm also not exactly sure what the phrase "retaining ...
xdevel2000's user avatar
  • 21.6k
119 votes
7 answers
448k views

I'm just learning the ropes of Spring 3's annotation fu and I've stumbled upon the newb's nightmare exception. Would appreciate any help. here's the form jsp code: <form:form method="POST" ...
KG -'s user avatar
  • 7,220
109 votes
2 answers
260k views

I use annotation in my code, and I try to use value which determine in run time. I define my list as static final (lst), and I add to this list some elements. When I use lst.get(i), I get ...
Cons's user avatar
  • 1,213
4 votes
1 answer
7k views

I have an XYPlot on which are series and a couple of dynamically added shape annotations with no fill (hence each of the series points are visible). Is it possible to display the series tool tips(that ...
jpo's user avatar
  • 4,079
138 votes
10 answers
107k views

I have an existing project that uses @Override on methods that override interface methods, rather than superclass methods. I cannot alter this in code, but I would like Eclpse to stop complaining ...
Stefan Kendall's user avatar
161 votes
5 answers
146k views

I'm exploring annotations and came to a point where some annotations seems to have a hierarchy among them. I'm using annotations to generate code in the background for Cards. There are different ...
javydreamercsw's user avatar
61 votes
5 answers
125k views

What is the equiv way in Jackson json annotation for the following jax-b annotations? I need to produce json rather than xml and need to know the conventional jackson annotations that is equivalently ...
Blessed Geek's user avatar
  • 21.8k
176 votes
7 answers
143k views

The JPA (Java Persistence API) specification has 2 different ways to specify entity composite keys: @IdClass and @EmbeddedId. I'm using both annotations on my mapped entities, but it turns out to be ...
sakana's user avatar
  • 4,531
55 votes
8 answers
42k views

Eclipse is adding @Override annotations when I implement methods of an interface. Eclipse seems to have no problem with this. And our automated build process from Cruise Control seems to have no ...
skiphoppy's user avatar
  • 104k
43 votes
3 answers
82k views

Lets say we have an entity Person, a controller PersonController and an edit.jsp page (creating a new or editing an existing person) Controller @RequestMapping(value = "/edit", method = ...
user711189's user avatar
  • 4,523
40 votes
2 answers
31k views

According to the Hibernate Reference Documentation it should be possible to mix different inheritance mapping strategies when using Hibernate's XML-Metadata: http://docs.jboss.org/hibernate/stable/...
Meeque's user avatar
  • 713
33 votes
11 answers
65k views

@Column(name="DateOfBirth") private Date dateOfBirth; I specifically need the above code to create a column named "DateOfBirth," instead Hibernate gives me a column named date_of_birth. How can I ...
lucas's user avatar
  • 6,971
24 votes
2 answers
62k views

The generic entity, super class: @MappedSuperclass public abstract class GenericEntity { private Integer id; public Integer getId() {return id;} public void setId(Integer id) {this.id = ...
BasicCoder's user avatar
  • 1,681
108 votes
3 answers
16k views

Consider the following code: A.java: import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) @interface A{} C.java: import java.util....
Matt McHenry's user avatar
  • 21.2k

1
2 3 4 5
38