Solved

Annotated Resource loading properties from database

Posted on 2013-01-13
3
163 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 35

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 35

Accepted Solution

by:
mccarl earned 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
noX challenge 17 77
topping1 challenge 7 53
Running Jira on Raspberry PI 2? 3 139
JAVA part two 5 42
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now