IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

spring:spring的核心API

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

1、BeanFactory接口

BeanFactory接口为Spring的原始接口,功能较为单一,其特点是,每次在获得对象的时候才会创建对象,而ApplicationContext 是事先创建对象,需要的时候直接从容器中去即可。BeanFactory是一个工厂,用于生成任意bean。

2、ApplicationContext 类

(1)介绍:

每次容器创建的时候就会创建容器中所配置的对象,并且功能有很大的增强。但是,ApplicationContext较为浪费资源,因为它将所有的对象一次全部创建出来,而BeanFactory是在调用和对象的时候才会去创建对象。

(2)ApplicationContext 获取配置文件的方法:

从类路径下获取配置文件:

 ApplicationContext applicationContext=new
                ClassPathXmlApplicationContext("applicationContext.xml");//创建容器对象

从硬件绝对路径下获取配置文件(指定盘符下的xml):

FileSystemXmlApplicationContext("路径")

3、ApplicationContext 类与BeanFactory接口的对比

(1)ApplicationContext 类:

StudentServiceImpl:
public class StudentServiceImpl {
    private StudentDao studentDao;

    public StudentServiceImpl() {
        System.out.println("service的实现类被创建了!!");
    }

    public StudentDao getStudentDao() {
        return studentDao;
    }
    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
    }
    public void addStudent(){
        System.out.println("StudentService的实现类的Add方法!!");
        studentDao.addStudent();
    }
}

测试类:

  public static void main(String[] args) {
        ApplicationContext applicationContext=new
                ClassPathXmlApplicationContext("applicationContext.xml");//创建容器对象
        StudentServiceImpl studentService=(StudentServiceImpl) applicationContext.getBean("studentService");
        studentService.addStudent();
    }

测试结果:

service的实现类被创建了!!
StudentService的实现类的Add方法!!
StudentDao的实现类的Add方法!!

(2)BeanFactory接口

   public static void main(String[] args) {
        BeanFactory beanFactory=new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
        StudentServiceImpl studentService=(StudentServiceImpl) beanFactory.getBean("studentService");
        studentService.addStudent();
    }

在调用getBean的时候才会去创建对象

文章永久链接:https://tech.souyunku.com/?p=23318


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(79) 打赏



未经允许不得转载:搜云库技术团队 » spring:spring的核心API

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367