記事のディレクトリ
SpringIOCケース(JDBCデータベース):XML設定
1. bean.xml設定コンテキストタグ
図2は、(変化の主な点で、データソースが使用XML構成で配置されている構成QueryRunnerオブジェクトの残り):
最初のポイント:注釈ヘッダ構成に変更されている
第二の点:(1)コンフィギュレーションサービス層(2)の層構成ダオを交換しますコンテキストタグの
追加コンテンツ
<?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:context="http://www.springframework.org/schema/context"
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.xsd">
<!--注解配置:告知Spring在创建容器时要扫描的包-->
<context:component-scan base-package="com.jh"></context:component-scan>
変化に対する各層の2. XML構成
1.dao层
- AccountDaoImpl実装クラスの変更:
(1)セットを削除し、メソッドを取得し、回避ヌルポインタ例外にするために、@Autowiredノート;
プラス創造Beanオブジェクト・ノート(2)@Repository(「AccountDao」)
(3)は、コードの残りの部分に従う
コードを変更します
@Repository("accountDao")
public class AccountDaoImpl implements IAccountDao {
@Autowired
private QueryRunner runner;
- IAccountDaoインターフェイスの変更なし
2.ドメイン層変わらず
3.サービス層
- AccountServiceImplビジネスレイヤ変更:
同じ変更DAO層、コードの変更
@Service("accountService")
public class AccountServiceImpl implements IAccountService {
@Autowired
private IAccountDao accountDao;
- 変わらずIAccountService
4. AccountServiceTest変わらず