在src目录下创建dao包
在dao包下创建接口TestDao

package dao;

public interface TestDao {
    public void sayHello();
}

创建实现类TestDaoImpl

package dao;

public class TestDaoImpl implements TestDao {
    @Override
    public void sayHello(){
        System.out.println("Test1");
    }
}

创建spring配置文件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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="testDao" class="dao.TestDaoImpl"/>
</beans>

在test包下创建Test类

package test;

import dao.TestDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        TestDao testDao = (TestDao) ac.getBean("testDao");
        testDao.sayHello();
    }
}

结果

4月 06, 2019 10:48:25 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3dd4520b: startup date [Sat Apr 06 10:48:25 CST 2019]; root of context hierarchy
4月 06, 2019 10:48:25 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [ApplicationContext.xml]
Test1