2009年8月21日 星期五

spring 的 annotation @Value 介紹

通常在 bean.xml 裡我們常以 value 注入單純的資料,如 int,string、
也會注入 properties 檔裡的變數資料,如:
x-setting.properties -
com.transtep.xdna.doc.projplan.docDirLocation=tpma_doc

x-bean.xml -
<property name="docDirLocation">
<value>${com.transtep.xdna.doc.projplan.docDirLocation}</value>
</property>

但spring 3.0 使用 annotation 的時候,x-bean.xml 有些 bean 就不需要再宣告了,如 @Controller
而是自動讓 spring 去 scan 某 package 找到的,如此一來就無法注入 value
在 spring 3.0.M3 時加入了 @Value 這一個方便的 annotation 讓我們可以重拾 value 注入。
用法:

@Value("${com.transtep.xdna.doc.projplan.docDirLocation}")
private String docDirLocation = "";

20 則留言:

  1. Everything is very open with a very clear explanation of the challenges.
    It was truly informative. Your site is extremely helpful.
    Thanks for sharing!
    Also visit my blog post Http://Tlm.tudelft.nl

    回覆刪除
  2. Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I submitted and say, I'm thoroughly enjoying your blog.
    I as well am an aspiring blog blogger but I'm still new to everything. Do you have any tips for rookie blog writers? I'd
    certainly appreciate it.
    My web blog :: a4Articles.In

    回覆刪除
  3. It's really a great and helpful piece of information. I'm glad that you
    just shared this helpful info with us. Please stay us up to date like this.

    Thanks for sharing.
    My page > http://wiki.fonacier.net/index.php?title=User:RetaPfx

    回覆刪除
  4. If some one wishes to be updated with newest technologies after that he must be visit this web page and be up to date all the time.
    Here is my blog post ... instantloan960

    回覆刪除
  5. I am regular reader, how are you everybody? This piece of writing
    posted at this site is actually good.
    my site > craftworldgame.com

    回覆刪除
  6. I could not resist commenting. Very well written!
    Feel free to surf my webpage quickcashloan

    回覆刪除
  7. whoah this blog is great i like studying your posts.
    Stay up the good work! You realize, lots of people are searching round for this information, you
    can aid them greatly.
    My website : http://wiki.alarm112.pl

    回覆刪除
  8. Saved as a favorite, I love your blog!
    Also visit my blog : http://www.lytecube.com/

    回覆刪除
  9. When some one searches for his necessary thing, thus he/she wishes to be available that
    in detail, so that thing is maintained over here.
    Also visit my web site : Www.Lesandlynnessocialsite.Com

    回覆刪除
  10. Does your site have a contact page? I'm having trouble locating it but, I'd like to shoot you an email.

    I've got some suggestions for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.
    Stop by my weblog cornell.edu

    回覆刪除
  11. I was able to find good info from your blog posts.
    Feel free to visit my website iarticledirect.com

    回覆刪除
  12. Good day! I could have sworn I've been to this website before but after looking at some of the articles I realized it's new to
    me. Anyways, I'm definitely happy I came across it and I'll
    be bookmarking it and checking back frequently!
    Also visit my web page ... quickcashloans

    回覆刪除
  13. I'm impressed, I must say. Rarely do I come across a blog that's both equally educative and interesting, and without a doubt,
    you've hit the nail on the head. The issue is an issue that too few folks are speaking intelligently about. I'm very happy that I stumbled across this in my hunt for something regarding this.
    Feel free to visit my website : community.i-for-you.com

    回覆刪除
  14. Way cool! Some extremely valid points! I appreciate you writing this post and also the rest of the site is extremely good.
    Feel free to surf my weblog : http://giapiver.altervista.org/groups/same-day-loans-fast-loan-for-immediate-needs-any-time-of-the-month/

    回覆刪除
  15. Does your website have a contact page? I'm having trouble locating it but, I'd like to send you an email.

    I've got some creative ideas for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.
    Check out my blog ; forum.Farmdirector.com

    回覆刪除
  16. I leave a leave a response each time I especially enjoy
    a post on a website or I have something to valuable to contribute
    to the discussion. It is caused by the fire communicated in the article I read.
    And after this article "spring 的 annotation @Value 介紹".

    I was actually excited enough to post a thought :-) I actually do have a couple
    of questions for you if you usually do not mind. Could it be only
    me or does it look like a few of these remarks come across like
    left by brain dead people? :-P And, if you are writing on additional sites, I'd like to follow you. Could you make a list every one of your community sites like your Facebook page, twitter feed, or linkedin profile?
    Also visit my blog ... instant loans

    回覆刪除
  17. It's an awesome paragraph in favor of all the internet viewers; they will obtain advantage from it I am sure.

    Also visit my webpage: buy facebook Page likes uk

    回覆刪除
  18. Wonderful post! We will be linking to this great
    article on our website. Keep up the great writing.

    my weblog SocialBooster

    回覆刪除
  19. My brother suggested I might like this blog. He was entirely right.
    This post truly made my day. You can not imagine just how
    much time I had spent for this information! Thanks!

    my weblog :: http://wiki.piratupartija.lv/index.php?title=Lietotājs:NigelTrem

    回覆刪除
  20. I'm not sure where you're getting your information, but great
    topic. I needs to spend some time learning much more
    or understanding more. Thanks for fantastic info I was looking for this information for my mission.



    Feel free to visit my blog post; buy 200 twitter followers cheap

    回覆刪除