1、创建一个新的项目,并添加Spring框架

2、创建HelloWorld.java

package com.broadtext.beans.helloworld;

public class HelloWorld {
private String name; public HelloWorld() {
} @Override
public String toString() {
return "HelloWorld [name=" + name + "]";
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}

3、修改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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> <bean id="helloWorld" class="com.broadtext.beans.helloworld.HelloWorld">
<property name="name" value="hjj"></property>
</bean> </beans>

这时候HelloWorld.java文件上会多出'S'标记

4、添加Main.java和Main方法测试HelloWorld bean

package com.broadtext.beans.helloworld;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
System.out.println(helloWorld);
} }

5、运行,看看控制台打印的HelloWorld

Spring框架学习笔记(1)——HelloWorld的更多相关文章

  1. Spring MVC 学习笔记一 HelloWorld

    Spring MVC 学习笔记一 HelloWorld Spring MVC 的使用可以按照以下步骤进行(使用Eclipse): 加入JAR包 在web.xml中配置DispatcherServlet ...

  2. Spring框架学习笔记(5)——Spring Boot创建与使用

    Spring Boot可以更为方便地搭建一个Web系统,之后服务器上部署也较为方便 创建Spring boot项目 1. 使用IDEA创建项目 2. 修改groupid和artifact 3. 一路n ...

  3. Spring框架学习笔记(8)——spring boot+mybatis plus+mysql项目环境搭建

    之前写的那篇Spring框架学习笔记(5)--Spring Boot创建与使用,发现有多小细节没有提及,,正好现在又学习了mybatis plus这款框架,打算重新整理一遍,并将细节说清楚 1.通过I ...

  4. Spring框架学习笔记(1)

    Spring 框架学习笔记(1) 一.简介 Rod Johnson(spring之父) Spring是分层的Java SE/EE应用 full-stack(服务端的全栈)轻量级(跟EJB比)开源框架, ...

  5. 手写Spring框架学习笔记

    以下是咕泡公开课的学习笔记 一.创建工程springdemo 二.在pom中配置servlet <dependency> <groupId>javax.servlet</ ...

  6. Spring框架学习笔记(3)——SpringMVC框架

    SpringMVC框架是基于Spring框架,可以让我们更为方便的进行Web的开发,实现前后端分离 思路和原理 我们之前仿照SpringMVC定义了一个自定义MVC框架,两者的思路其实都是一样的. 建 ...

  7. spring框架学习笔记7:事务管理及案例

    Spring提供了一套管理项目中的事务的机制 以前写过一篇简单的介绍事务的随笔:http://www.cnblogs.com/xuyiqing/p/8430214.html 还有一篇Hibernate ...

  8. spring框架学习笔记6:JDBC模板

    JDBC模板:Spring中对数据库的操作. 这一部分对熟悉DBUtils的QueryRunner的开发者来说,非常简单 这是以前我简单写的dbutils的知识: http://www.cnblogs ...

  9. spring框架学习笔记1:搭建测试

    Spring框架介绍: Spring框架涵盖了web.service.dao三层,本身是一个存放对象的容器 形象来说:Spring是项目中对象管家 Spring框架的两大核心思想:控制反转(IOC). ...

随机推荐

  1. Docker安装入门 -- 中间件镜像

    Docker安装入门 -- 中间件镜像 php-fpm 1.docker build -t csphere/php-fpm:5.4 .   //在当前目录下创建镜像 2.docker run -d - ...

  2. Java_Date_01_判断两个时间相差的天数

    二.参考资料 1.java 判断两个时间相差的天数 2.java计算两个日期之间相差天数和相隔天数详解

  3. h5拖拽上传图片

    h5实现拖拽上传图片 本文将为大家介绍如何通过js实现拖拽上传图片. 首先我们要禁用调浏览器默认的拖拽事件: window.onload = function(){ //拖离 document.add ...

  4. SQL 多列合并一列

    select rtrim(姓)+ rtrim(名) as 姓名 from tb

  5. 用 HAproxy 搭建 RabbitMQ 集群

    构建参考: [ Rabbitmq cluster setup with HAproxy ] [ python demo ] RabbitMQ Cluster 遇到的问题 python pika 作为c ...

  6. HTML + CSS短标题(二,三,四文字长度)两端对齐的方式

    今天切图碰到了一个看似好弄,却并不好弄的文本两端对齐问题.如图1-1

  7. table-cell实现未知宽高图片,文本水平垂直居中在div

    <BODY> <h1>未知宽高的图片水平垂直居中在div</h1> <!--box-outer--> <div class="box-o ...

  8. Ubuntu 16.04 LTS运行robo3t报错

    系统环境:Ubuntu 16.04 LTS. 安装robomongo Robo 3T,运行时报以下错误: jaxu@jaxu-ubuntu:/usr/local/share/robo3t--linux ...

  9. Specified key was too long max key length is 1000 bytes

    Mysql建立索引时遇到一个问题就是索引字段长度太长,解决办法: 1.修改字段长度 : 2.修改mysql默认的存储引擎 ,修改为INNODB: https://www.2cto.com/databa ...

  10. http转https实战教程iis7.5

    HTTP转HTTPS实战教程IIS7.5 (备注:确保IIS安装完成.ASP.NET 等配置无误) 1.          本文以阿里云为例,先在阿里云注册域名并且进行备案.备案完成后,在左侧菜单申请 ...