🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
就是各种hello-world项目 ![](https://img.kancloud.cn/c3/b6/c3b64547e9b710d545e969e50ccaa837_426x743.png) 从最简单经典的hello-world 到使用设计模式解耦的版本 最终到使用 Spring 框架依赖注入的版本。 包含了一个 xml 配置的 spring 容器 `app-context.xml` 内容如下: ```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:p="http://www.springframework.org/schema/p" xsi:schemaLocation= "http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> <!--xml方式定义两粒bean--> <bean id="provider" class="com.apress.prospring5.ch2.decoupled.HelloWorldMessageProvider"/> <!--id和class,还有p命名空间--> <bean id="renderer" class="com.apress.prospring5.ch2.decoupled.StandardOutMessageRenderer" p:messageProvider-ref="provider"/> </beans> ``` 还有很简单的单元测试: ```java // 省略 import 语句 public class TestHelloWorldSpringAnnotated { @Test public void testHello() { ApplicationContext ctx = new AnnotationConfigApplicationContext (HelloWorldConfiguration.class); MessageRenderer mr = ctx.getBean("renderer", MessageRenderer.class); assertNotNull(mr); } } ```