728x90
반응형

앞글 ( http://tylee82.tistory.com/61 )에 이은 포스트입니다.
이 글은 머드초보의 블로그 ( http://mudchobo.tomeii.com/tt/238?category=8 )의 글을 기초로 작성 됨을 알려드리며, 문제 발생시 자삭하겠습니다.

<< Manager클래스 작성 >>
실제로 BlazeDS를 이용해서 가져오는 놈은 이 Manager클래스가 됩니다.
Java Resources: src에서 오른쪽버튼 클릭하고, New를 해서 interface를 구현합니다.

package springapp.service;

import java.util.List;
import springapp.domain.Product;

public interface ProductManager {
 
public List<Product> getProducts();
}

getProducts라는 메소드가 하나 있군요! 구현해봅시다!!!

package springapp.service;

import java.util.List;

import springapp.dao.ProductDao;
import springapp.domain.Product;

public class ProductManagerImpl implements ProductManager {

 
private ProductDao productDao;
 
 
@Override
 
public List<Product> getProducts() {
 
return productDao.getProductList();
 
}

 
public void setProductDao(ProductDao productDao) {
 
this.productDao = productDao;
 
}
}

getProducts라는 함수는 Dao에서 getProductList를 호출하는 놈이네요.
요 아래에는 setter가 있네요. 이건 spring에서 DI를 하기위해 존재하는 setter입니다^^
서비스도 완성이 되었네요! 이제 설정파일을 작성해봅시다.

WEB-INF/applicationContext.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:aop="http://www.springframework.org/schema/aop"
 
xmlns:tx="http://www.springframework.org/schema/tx"
 
xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
>

 
<!-- Enable @Transactional support -->
 
<tx:annotation-driven />

 
<!-- Enable @AspectJ support -->
 
<aop:aspectj-autoproxy />

 
<aop:config>
 
<aop:advisor pointcut="execution(* *..ProductManager.*(..))"
   
advice-ref="txAdvice" />
 
</aop:config>

 
<tx:advice id="txAdvice">
 
<tx:attributes>
   
<tx:method name="save*" />
   
<tx:method name="get*" read-only="true" />
 
</tx:attributes>
 
</tx:advice>

 
<bean id="productManager"
 
class="springapp.service.ProductManagerImpl">
 
<property name="productDao" ref="productDao" />
 
</bean>

</beans>

Dao부분의 설정파일인 applicationContext-ibatis.xml파일을 봅시다.
WEB-INF/applicationContext-ibatis.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:aop="http://www.springframework.org/schema/aop"
 
xmlns:tx="http://www.springframework.org/schema/tx"
 
xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
>

 
<bean id="propertyConfigurer"
 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
 
p:location="classpath:properties/jdbc.properties" />

 
<bean id="dataSource"
 
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
 
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
 
p:username="${jdbc.username}" p:password="${jdbc.password}" />

 
<!-- Transaction manager for iBATIS Daos -->
 
<bean id="transactionManager"
 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 
<property name="dataSource" ref="dataSource" />
 
</bean>

 
<!-- SqlMap setup for iBATIS Database Layer -->
 
<bean id="sqlMapClient"
 
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
 
<property name="dataSource" ref="dataSource" />
 
<property name="configLocation"
   
value="classpath:springapp/dao/SqlMapConfig.xml" />
 
</bean>

 
<!-- Add additional Dao definitions here -->
 
<bean id="productDao"
 
class="springapp.dao.ProductDaoImpl">
 
<property name="sqlMapClient" ref="sqlMapClient" />
 
</bean>
 
</beans>

jdbc.properties파일은 properties라는 package를 만들고, jdbc.properties파일을 넣어버립시다.

jdbc
.driverClassName=com.mysql.jdbc.Driver
jdbc
.url=jdbc:mysql://DB주소
jdbc
.username=DB아이디
jdbc
.password=DB비밀번호

이 설정들의 bean들의 관계를 보고 싶다면-_-;
Spring Elements에서 오른쪽버튼 클릭하고 properties를 선택.
Bean Support를 선택, Add한 뒤 두개의 설정파일(applicationContext.xml, applicationContext-ibatis.xml)선택.
Config set에서 New하고 Name에 applicationContext라고 하고, 두개다 체크 오케이~
그럼 이제 스프링 설정파일에서 에러를 찾아낼 수 있어요!
bean들의 관계를 그래프로도 볼 수 있네요!
Config set에 추가한 applicationContext에다가 마우스오른쪽버튼을 클릭하면 open graph로 볼 수 있어요!

이제 클라이언트 구현으로....다음 시간에-_-;
728x90
반응형

+ Recent posts