Spring基础(一) 启用注解形式

启动注解:

    
	
package com.example.demo.learn.aop;


import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDemo {
    private static String path = "config/applicationContext.xml";
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(path);
        TagService tagService = context.getBean("tagService", TagService.class);
        tagService.test();
    }
}
package com.example.demo.learn.aop;

import org.springframework.stereotype.Service;

@Service
public class TagDao {
    public void add() {
        System.out.println("数据库层操作...");
    }
}
package com.example.demo.learn.aop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TagService {

    @Autowired
    private TagDao tagDao;

    public void test() {
        System.out.println("测试数据.....");
        tagDao.add();
    }
}

 

 

你可能感兴趣的:(Spring基础(一) 启用注解形式)