반응형

SpEL
- Expression Languege중 하나, 런타임시 특정 객체의 정보에 접근하거나 조작할수 있도록 지원.

1. XML 기반 Bean 정의시

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
        <property name="driverClassName" value="#{contextProperties.driver}"> 
        <property name="url" value="#{contextProperties.url}"> 
        <property name="username" value="#{contextProperties.username}"> 
        <property name="password" value="#{contextProperties.password}"> 
</property></property></property></property></bean>

classpath상에 존재하는 context.properties파일을 로드하여 bean으로 정의한 후 driver, url 등의 정보를 추출함.

2. Annotation 기반 Bean 정의시

  1. @Repository(“movieDao")
  2. public class MovieDao extends SimpleJdbcDaoSupport {
  3.  
  4.        @Value("#{contextProperties['pageSize'] ?: 10}")
  5.        int pageSize;
  6.        @Value("#{contextProperties['pageUnit'] ?: 10}")
  7.        int pageUnit;
  8.        @Inject
  9.        public void setJdbcDaoDataSource(DataSource dataSource) throws Exception {
  10.                  super.setDataSource(dataSource);
  11.        }
  12. }
@Value라는 Annotation과 함께 Expression정의 (값이 없을 경우 10으로 셋팅)

728x90
반응형

'Development > Java' 카테고리의 다른 글

파일 입출력.  (0) 2013.01.29
[Spring]Spring Annotation  (0) 2012.08.01
[Spring]Autowiring  (0) 2012.05.03
[Spring]AOP 주요 구성요소  (0) 2012.04.13
[Spring]Spring Bean Scope  (0) 2012.04.09

+ Recent posts