Spring
어노테이션 설정 기초
context 네임스페이스
컴포턴트 스캔 설정
@Component 가 설정된 클래스들을 자동으로 객체 생성
생성한 객체 요청하기 위해선 아이디 또는 이름 설정이 되어있어야 한다.
@Component("id 또는 이름")
의존성 주입 어노테이션
@Autowired
주로 변수위에 설정하여 해당 타입의 객체를 찾아서 할당한다.
@Inject
@Qualifier 와 @Autowired의 기능을 결합한 어노테이션이다.
@Qualifier
특정객체의 이름을 이용하여 의존성 주입할 때 사용한다.
@Resource
@Autowired와 동일한 기능을 재공한다.
우선적으로 아래와 같은 사항을 확인한다.
1. 톰캣이 정상동작 하는지 ?
2. pom.xml의 수정이 오류가 있지 않는지 ?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<context:component-scan base-package="com.springbook.biz"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="log" class="com.springbook.biz.common.LogAdvice"> </bean>
<aop:config>
<aop:pointcut id="allPointcut"
expression="execution(* com.springbook.biz..*Impl.*(..))" />
<aop:aspect ref="log">
<aop:before method="printLog" pointcut-ref="allPointcut" />
</aop:aspect>
</aop:config>
</bean>
PropertyPlaceConfigurer를 이용하면 외부의 프로퍼티 파일을 참조하여 DataSource를 설정할 수 있다.