Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Annotated Resource loading properties from database

Posted on 2013-01-13
3
Medium Priority
?
176 Views
Last Modified: 2013-05-30
I'm working on developing custom annotation which will pull values from datasource at runtime. I need immediate help on this task.

For e.g. Following class has defined annotated field pageTitle which will pull value for given parameter (rLable) from spring defined datasource at runtime i.e. getPageTitle() should return value for key "label.page.title" from database which is "My Page Title".

Class ResourceDataVO {

@myResources (rLabel = "lable.page.title")
String pageTitle;
....

public String getPageTitle(){
	return this.pageTitle;
}
}

Open in new window

0
Comment
Question by:sanjaykjadhav
  • 2
3 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 38772888
I need immediate help on this task
Perhaps, you should immediately ask your question then!
0
 

Author Comment

by:sanjaykjadhav
ID: 38772894
How to develop annotation accessing database? Please explain based on above usage of annotation.
0
 
LVL 36

Accepted Solution

by:
mccarl earned 1500 total points
ID: 38772977
Firstly, you need to learn what Java Annotations are and what they are NOT!

They *are* a way to provide meta-data about a class/method/field/etc. And this meta-data can be accessed at compile time by compilers,etc or at runtime by your code or other code.

They are *NOT* of themselves active elements that can directly execute code, etc.


Therefore, to achieve what you are trying to do, you need some sort of annotation processor. This will look for your particular custom annotation and apply the desired behaviour that you are trying to achieve. How, and when and in what context this annotation processor runs is enitrely up to you, and it will depnd on exactly when you need this behaviour to have been applied.

You did mention Spring in the original problem statement, so one Spring like way of doing this would be with a BeanPostProcessor instance. Look at the code for say InitDestroyAnnotationBeanPostProcessor for an idea on what your code might have to do, in terms on scanning for an annotation on the bean that is being constructed. Obviously, your code would be different in terms of it needing to interface with the datasource to retrieve value(s) and populate them in the bean. You then just create an instance of your BeanPostProcessor within your appContext and then Spring takes care or running it for you when you instantiate your beans.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question