3.0에 추가된 SpEL의 활용방법은 매우 다양하다. SpEL을 사용하면 기존에 애용되던 ${}와 <context:property-placeholder>를 대체할 수도 있다.

${}로 property place holder를 만들어 두고 프로퍼티 파일을 읽어서 value를 바꿔치기 하는 방법은 환경에 따라서 자주 변하는 DB연결정보와 같은 설정정보를 XML이나 소스코드에서 분리시킬 수 있다는 장점이 있다. SRP에 따르면 responsibility, 즉 변하는 이유가 다르면 분리해야 한다. 설정 정보도 마찬가지다.

${} 방식의 단점은 프로퍼티 파일의 키 값에 ${ prefix와 } suffix를 붙여서 find-and-replace 방식으로 동작한다는 점이다. 매칭되는 키 값이 존재하지 않으면 ${} 부분이 그대로 남을 수 있다. 설정을 빼먹은 것이라면 모르겠지만 오타로 인해서 이름을 잘못 적거나 ${}을 제대로 넣지 않아도 경고 없이 그냥 넘어간다. 내부적으로는 BFPP에 의해서 동작하는 것이므로 ${}을 가진 빈 입장에서는 수동적이다. 남이 변경해주면 고맙고 아니어도 불평을 할 수 없다.

반면에 SpEL을 사용하는 방법은 능동적이다. SpEL로 property-placeholder를 대체하면 BFPP를 사용하지 않아도 된다. <util:properties>를 이용해서 프로퍼티 파일을 Properties 타입의 빈으로 생성하게 하고 다른 빈 오브젝트에 접근할 수 있는 SpEL을 이용해서 원하는 프로퍼티 값을 찾아오게 만들면 된다.

<util:properties id=”dbpr” location=”…” /> 이라고 되어있다면,

<property name=”username” value=”#{dbpr[‘username’]}” /> 으로 만들어주면된다. []는 Map 오브젝트의 get()을 호출해주는 SpEL의 표현이다.

SpEL은 능동적이다. 자기가 필요한 정보를 원하는 프로퍼티 정보를 담은 빈에 가서 직접 찾아오는 것이다. Properties빈이 존재하지 않으면 에러도 발생시켜준다. 물론 Map의 get()이라 키에 해당하는 값이 없어도 그냥 null이 들어간다는 한계는 있다. 수식을 좀 길게 쓰면 null인 경우에 오류가 발생하게 만드는 것도 가능할 것이다.

${}는 기존 설정의 호환성과 익숙한 방식의 집착 때문에라도 앞으로 오랜동안 사용될 것이다. context 스키마에서 직접 지원해주는 기능이기도 하고. 하지만 나는 SpEL을 사용하는 능동적인 방식으로 모두 바꿀 생각이다. 더 명시적이고, 구체적이고, 이해하기 쉽고, 오류도 잘 잡아주는 SpEL 방식이 더 맘에 들기 때문이다.

Related posts:

  1. Spring 3.0 EL (Spel)을 이용한 AssertThrows 확장 (3)
  2. Spring 3.0 EL (Spel)을 이용한 AssertThrows 확장 (2)
  3. Spring Expressions(SpEL)를 이용한 Mockito Argument Matcher 만들기
  4. Spring 3.0 EL (Spel)을 이용한 AssertThrows 확장 (1)
  5. 스프링 컨테이너에는 설정파일이 없다
  6. 톰캣 앞에 아파치 웹 서버(Httpd)를 두어야 할까?
  7. Maven archetype 설정파일 자동생성기 – ArchetypeXmlWriter
  8. 파이썬 완벽 가이드 전자책
  9. Spring 2.0의 XML확장기능 (1)
  10. 스프링 3.1 (7) 프로퍼티 소스 추상화와 PropertySourcePlaceholderConfigurer
  11. Inside Spring (5) PropertyPlaceholderConfigurer를 @Bean으로 정의해서는 안되는 이유
  12. Spring 3.0 (28) R-669 Update
  13. Spring 3.0 (52) 반쪽짜리 3.0 RC1 공개
  14. Spring 3.0 (36) Field Marker와 Field Default
  15. Spring 3.0 (2) R-518 스프링의 새 모듈 OXM(Object/XML Mapping)

Facebook comments:

to “Spring 3.0 (59) 프로퍼티 파일 이용하기 – placeholder vs SpEL”

  1. majestic baseball jersey.Our online shop will stock the entire range of majestic baseball jersey australia together with some fantastic discounted cheap jersey supply,it’s your pleasure to buy it with free shipping.

  2. Cubs 17 Kris Bryant White Strip New Cool Base Stitched MLB Jersey.Where
    to order purple baseball jersey?
    Collect Islanders 91 John Tavares Stitched Light Blue NHL
    Jersey varous sizes, which is crazy fashion now.

  3. I see you don’t monetize your page, don’t waste your traffic, you can earn extra
    bucks every month because you’ve got hi quality content.
    If you want to know how to make extra $$$, search for: Mertiso’s tips best
    adsense alternative

  4. I have checked your page and i’ve found some duplicate content, that’s why you don’t rank
    high in google’s search results, but there is a
    tool that can help you to create 100% unique content, search for; Boorfe’s tips unlimited content

  5. Hi I really enjoyed reading this content

  6. Nike Cowboys 82 Jason Witten White Mens Stitched NFL Elite Jersey.Nike Cowboys 82 Jason Witten White Mens
    Stitched NFL Elite Jersey-Welcome to buy cheap wholesale Nike Vikings 19 Adam Thielen Purple Team Color Mens Stitched NFL Elite
    Jersey with free shipping and best service in our jerseys online shop.

  7. You could make use of the discount rate code HostingTavern”
    best rated canister vacuum for pet hair – Ada – $50 off if you make a decision to purchase as well as utilize along side GSA.

  8. I have checked your page and i have found some
    duplicate content, that’s why you don’t rank high in google,
    but there is a tool that can help you to create
    100% unique content, search for; Best article rewritwer Ercannou’s essential tools

  9. Dress Elegantly
    When purchasing a property you are able to lessen your house owner’s insurance amount by purchasing a home around a fireplace office. The better you are, the more reward you will definitely get and for that reason the higher discount on the rates. Don’t forget to place flame extinguishers all around your home for even more security.
    Sleeping much more up-right. Increasing your upper body can alleviate equally gravity and strain, allowing you to have a complete night’s relax without the need of heavy snoring. Use pillows or place some bricks within the headboard. Just a slight height can stop you from heavy snoring, so give it a try to see what level works for you.
    Nike Air Huarache Womens
    To perform properly in currency trading, you have to review the essential methods of marketplace assessment. It can be difficult to do well in forex trading should you not use a strong understanding of the guidelines in the approach. Knowing industry assessment will help you to make informed and rewarding selections.

  10. Masteron Hair Loss Permanent
    While using tips and tricks that you’ve just read through, you can allow yourself a great head start in developing a imaginative and different photography profile. This knowledge will allow you to as you may create your talent in portraiture, landscape digital photography, sports activities and measures pictures, and even macro photos that give you in close proximity and private together with your subject matter.Superb Style Ideas That The Experts Use
    Anadrol Natural Alternative
    Since you now have an idea concerning how to increase your appearance you need to start to sense confident about you yet again. Lots of people don’t know the significance of establishing a great appearance for their own reasons, and they undergo existence never ever subsequent trends. However you can demonstrate individuals you already know excellent design after today.Earn The Battle In opposition to Depressive disorders Using These Helpful Tips
    Anavar Risks
    The greatest thing an pregnant mother can do for her unborn child’s wellness is always to give up smoking. A mum-to-be ought to talk with her physician or midwife for help and support. If you fail to give up, trim down! Research has revealed that women that are expectant and you should not quit, should attempt to restrict their selves to 5 tobacco per day. Even unless you give up, carry on and keep to the other instructions provided to you by the doctor, for example taking nutritional supplements and consuming sensibly.
    Dianabol Keifei 10mg

  11. Testosterone Cypionate Levels Chart
    If you are stressed out, you might sense not comfortable about sharing your issues with others. However, conversing freely about how you feel is important to experiencing better. Reports have confirmed that speaking with friends and family regarding your life will raise the responsibility that you might sense. Conversing it out can help you approach your thinking and figure out emotions which you failed to recognize right up until spoke regarding this out noisy.
    Winstrol R$
    In case your mortgage is at difficulty, do something to refinance as quickly as possible. While the case was previously that you may not rebuild a home loan until you possessed defaulted onto it, right now there are lots of steps it is possible to get just before hitting that point. This kind of financial triage is quite valuable, and can decrease the pain sensation of any house loan crisis.
    It seems goofy to advocate retaining your garden equipment nice and clean. It can be grime after all, but the dirt on your own equipment can harbour harmful bacteria and microbes that may infect your plants and flowers with sickness. Also the dampness in the earth could corrosion your tools prior to it dries out out. Wash them following every use and dried out them effectively to avoid corrosion.
    Methandienone Bayer Fake

  12. Testosterone Enanthate 1st Cycle
    Always keep a couple of things in your space or condo that happen to be wholesome, cheap as well as simple to consume. This will likely considerably minimize late-night fastfood works and can save you dollars because of this. Peanut butter, low fat yogurt and bagels are all excellent alternatives. In addition they do not have several unhealthy calories as fried chicken breast or hamburgers.
    Best Oral Steroids To Keep Gains
    Journey could be a wondrous experience. No definitely, it could be. With regards to touring to a different place and going through new people, traditions, and foods, it is genuinely anything of wonder. To begin studying some basic principles with regards to steps to make a strategy that works for you, reference the tips below.
    Anadrol 50 Side Effects
    Take far better care of your health. Despression symptoms is actually a indicate small devil plus it can make people forget the way to take better care of themselves and their well being. Depression also masks other thoughts, for example nervousness or anxiety, and discouraged folks may find their selves staying up later to the nighttime, simply to begin the following day sensing far worse. If you discover this is going on to you, set and maintain typical bedtimes. When you have sleep problems, exercise relaxation methods, including visualization or self-hypnosis, whilst in your bed.
    Tren 100 Reviews

  13. Master Kishan
    A few of the medicine that may be recommended to elderly people can cause persistent constipation. Two types of this type of treatment are diuretics and iron health supplements. You are able to take pro-lively steps to overcome this bowel irregularity. First of all, ingest at the very least seven servings of normal water daily. This will likely promote far better digestive operations. Also have far more fruits, fresh vegetables and cereals in your diet plans. These fiber content-unique foods support promote bowel regularity.
    Testosterone Enanthate Female
    An essential website marketing suggestion is usually to begin a blog that is certainly personalized to your website’s viewers. Retaining an up to date, useful website will allow you to connect with your viewers on a much deeper degree, providing them with understanding of your thoughts, likes and dislikes. This interconnection can help create a have confidence in using the market that can show helpful to your web marketing and advertising initiatives.
    Oxymetholone Drug Test
    Mildew is a very common allergen within several residences. It can be lowered by generally drying out all types of surface from the bathroom and kitchen after use. Fungus requires drinking water to develop, of course, if all surface areas are free of moisture, the mold are not able to grow. Also seem under your basins to be certain there are actually no spills which may permit mold to grow.
    Deca Durabolin Nuspojave

Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2017 Toby's Epril Suffusion theme by Sayontan Sinha