在src目录下创建annotation包
在annotation包下创建类AnnotationUser

package annotation;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class AnnotationUser {
    @Value("chenheng")
    private String uname;

    public String getUname() {
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }
}

创建spring配置文件annotationContext.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" 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">
    <!--配置自动扫描annotation包下的类-->
    <context:component-scan base-package="annotation"/>
</beans>

在test包下创建TestAnnotation类

package test;

import annotation.AnnotationUser;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestAnnotation {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("annotationContext.xml");
        AnnotationUser au = (AnnotationUser) ac.getBean("annotationUser");
        System.out.println(au.getUname());
    }
}

结果

信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5a8e6209: startup date [Sat Apr 06 11:41:21 CST 2019]; root of context hierarchy
4月 06, 2019 11:41:22 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [annotationContext.xml]
chenheng