当前位置: 代码迷 >> 综合 >> Spring基础(一) 启用注解形式
  详细解决方案

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

热度:13   发布时间:2023-10-08 17:38:02.0

启动注解:

    <!-- 开启注解权限 --><context:component-scan base-package="com.example.demo.learn.aop"/>
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 {@Autowiredprivate TagDao tagDao;public void test() {System.out.println("测试数据.....");tagDao.add();}
}

 

 

  相关解决方案