spring4.3.5基本配置
1.去官网下载必要的jar包,以及
;
2.新建一个web项目,在Window->Java->Build Path->User Libraries
按照步骤1,2把spring的jar放进去。
3.右键项目-》Build Path-》Configure Build Path-》
第1步选择User Library-》勾选Spring4.3,第2步选择commons-logging-1.2.jar。如此必要的jar包就导进来了。
接下来项目src下写一个类HelloSpring:
package spring; public class HelloSpring {
private String info;
public void setInfo(String info) {
this.info = info;
}
public void message()
{
System.out.println("hello "+info);
}
}
然后在src下写一个xml配置文件,比如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.0.xsd">
<!-- 配置需要被Spring管理的Bean(创建,创建后放在了Spring IOC容器里面) -->
<bean id="hello" class="spring.HelloSpring">
<!-- 配置该Bean需要注入的属性(是通过属性set方法来注入的) -->
<property name="info" value="zhangsan" />
</bean>
</beans>
接下来写一个测试类Test:
package spring; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloSpring hs = context.getBean("hello", HelloSpring.class);
hs.message();
}
}
测试类中的getBean第一个参数是和applicationContext.xml文件中的bean的id对应。
spring4.3.5基本配置的更多相关文章
- 2 Spring4 之Bean的配置
Spring4 之Bean的配置 1 IOC & DI 概述 IOC(Inversion of Control):其思想是反转资源获取的方向. 传统的资源查找方式要求组件向容器发起请求查找资源 ...
- spring4+websocket+nginx详细配置
实现的版本jdk1.7.0_25, tomcat7.0.47.0, Tengine/2.1.1 (nginx/1.6.2), servlet3.0, spring4.2.2 使用maven导入版本3. ...
- Spring4.0支持Groovy配置
介绍 前一段时间观注了一下Spring4.0的一些特性,当中就有对Groovy配置的支持.因为临时还没有很深入的研究.所以举个小样例来说明一下怎样支持Groovy配置. package shuai.s ...
- spring4.0.0的配置和使用
1.创建一个javaproject或者webproject,我创建的时webproject,编译器用的时myeclipse2013 2.在lib文件夹以下倒入spring须要的一些核心包例如以下 还需 ...
- 丢弃重口味的xml配置--spring4用groovy配置bean(转)
spring4之前,bean的配置可以主要分为两种方式,一种是使用基于xml,个人非常讨厌这种方式,因为明明一件很简单的事,放在xml中就会多了不少繁杂的信息.另一种方式,是从spring3.0开始, ...
- Spring4.X + spring MVC + Mybatis3 零配置应用开发框架搭建详解(1) - 基本介绍
Spring4.X + spring MVC + Mybatis3 零配置应用开发框架搭建详解(1) - 基本介绍 spring集成 mybatis Spring4.x零配置框架搭建 两年前一直在做后 ...
- SpringBoot-SpringMvc的Interceptor拦截器配置
Interceptor拦截器实现对每一个用户请求处理前后的业务处理,比如我们需要对用户请求进行响应时间的记录,需要记录请求从开始到结束所耗的时间,这时我们就需要用到拦截器了 下面我们以记录请求处理时间 ...
- Javaweb配置最全的数据源配置
DBCP DBCP是Apache推出的数据库连接池(Database Connection Pool). 操作步骤: 添加jar包: commons-dbcp-1.4.jar commons-pool ...
- Spring基础配置
从毕业到现在我一直从事Android开发,但是对JavaEE一直念念不忘,毕业校招的时候,一个礼拜拿了三个offer,岗位分别是Android.JavaEE和JavaSE,后来觉得Android比较简 ...
随机推荐
- python 100day notes (1)
x1 + x2 +x3 + x4 = 8 多少正整数解 上面的问题等同于将8个苹果分成四组每组至少一个苹果有多少种方案 即用三个隔板插7个空位. 答案C(7,3) =35 # __name__是Pyt ...
- leetcode上回溯法的使用
17 93 131 46(全排列) class Solution { public: vector<vector<int>> permute(vector<int> ...
- 53、tensorflow基本操作
import tensorflow as tf import numpy as np x_data = np.float32(np.random.rand(2,100)) print(x_data) ...
- windows 配置msys2环境
msys2是一个在windows下模拟类unix的环境,之所以叫环境,是用为他提供了部分unix shell类似的功能,这个环境使你像在unix上使用shell一样.看到msys2你可能想到是不是还有 ...
- 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'XXX'中的标识列指定显式值。
(来自:https://zhidao.baidu.com/question/494717175.html)第一条回复,原因和例子都有了,解释的很好. 插入数据时,自增长列是系统自动处理,不需要你来指定 ...
- yum安装LAMP
安装LAMP环境二进制包安装,先更新yum源,PHP 7.0.33 扩展可选 yum -y install mysql mysql-server mysql-devel httpd httpd-dev ...
- 微信小程序 获取用户信息并保存登录状态
微信小程序 获取用户信息并保存登录状态:http://www.360doc.com/content/18/0124/11/9200790_724662071.shtml
- Matplotlib ValueError: _getfullpathname: embedded null character
Traceback (most recent call last): File "<stdin>", line 1, in <module> File &q ...
- linux/unix下setuid/seteuid/setreuid/setresuid
其中setresuid()具有最清晰的语法: setresuid()被执行的条件有: ①当前进程的euid是root ②三个参数,每一个等于原来某个id中的一个 如果满足以上条件的任意一个,setre ...
- Spark使用Java读取mysql数据和保存数据到mysql
原文引自:http://blog.csdn.net/fengzhimohan/article/details/78471952 项目应用需要利用Spark读取mysql数据进行数据分析,然后将分析结果 ...