下面开始项目的搭建

使用 Java EE - Eclipse 新建一 Dynamic Web Project

Target Runtime 选 Apache Tomcat 7.0(不要选 Apache Tomcat 6.0,7 以后才支持 Servlet 3.0)。

点击 Next > 按钮。

默认的 Source folders 配置如下:

ps:可以根据需求自己编辑比如

删除默认的,增加以下四个并修改默认的输出目录为 WebContent\WEB-INF\classes:

src/main/java

src/main/resources

src/test/java

src/test/resources

点击Next

Configure web module settings 对话框勾选 Generate web.xml deployment descriptor 选项:

然后点击finish完成

这几个包或许是需要最少的包

-------------------------------------------------------

3.下面开始部署

把所需要的jar包ctrl c    ctrl v粘贴到lib目录

然后  添加进来

添加完的效果

然后新建两个类

一个实体类-----------------HelloWorldSpringBean

一个测试类(包含main函数)----------HelloWorldSpring

新建配置文件 -----------helloWorldSpring.xml

具体如下:

HelloWorldSpringBean

package chapter2.HelloWorldSpring;

public class HelloWorldSpringBean {

private String hello;

public String getHello(){

return hello;

    }

public void setHello(String hello){

this.hello=hello;

    }

public void show(){

        System.out.println("--message--"+getHello());

    }

}

一个属性,

以及对应的get   set方法

还有执行方法

HelloWorldSpring

package chapter2.HelloWorldSpring;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.FileSystemXmlApplicationContext;

public class HelloWorldSpring {

public static void main(String[] args) {

// TODO Auto-generated method stub

        ApplicationContext ctx = new FileSystemXmlApplicationContext("src/helloWorldSpring.xml");

        HelloWorldSpringBean helloWorldSpringBean = (HelloWorldSpringBean)ctx.getBean("myHelloWorld");

        helloWorldSpringBean.show();

    }

}

helloWorldSpring.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="myHelloWorld" class="chapter2.HelloWorldSpring">

<property name="hello">

<value>hello World spring!</value>

</property>

</bean>

</beans>

HelloWorldSpring直接run as application 执行,报错

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 2 in XML document from file [D:\ProgramData\Workspaces\eclipse\chapter2\src\helloWorldSpring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

配置文件开头不能有其他内容空格或者空行等,如果有的话就会报错

XML没有以<?xml version="1.0" encoding="UTF-8"?> 开头,也就是说第一个字符必须是<?xml......

解决方法:

规范的XML格式、

<?xml version="1.0" encoding="UTF-8"?>  必须是XML文件的第一个元素且前面不能空格。

修改后继续报错,错误内容为

十一月 10, 2015 5:50:10 下午 org.springframework.context.support.FileSystemXmlApplicationContext refresh

警告: Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [chapter2.HelloWorldSpring] for bean with name 'myHelloWorld' defined in file [D:\ProgramData\Workspaces\eclipse\chapter2\src\helloWorldSpring.xml]; nested exception is java.lang.ClassNotFoundException: chapter2.HelloWorldSpring

    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1351)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:628)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)

    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1444)

    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:974)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:752)

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)

    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)

    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)

    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)

    at chapter2.HelloWorldSpring.HelloWorldSpring.main(HelloWorldSpring.java:12)

Caused by: java.lang.ClassNotFoundException: chapter2.HelloWorldSpring

类找不到,发现是配置文件中的class中写错了,没有写好类名

class="chapter2.HelloWorldSpring.HelloWorldSpringBean">修改为这个重新运行,可以打开

最终的代码为:

package chapter2.HelloWorldSpring;

public class HelloWorldSpringBean {

private String hello;

public String getHello(){

return hello;

    }

public void setHello(String hello){

this.hello=hello;

    }

public void show(){

        System.out.println("--message--"+getHello());

    }

}

---------------------------------------------------------

package chapter2.HelloWorldSpring;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.FileSystemXmlApplicationContext;

import chapter2.HelloWorldSpring.HelloWorldSpringBean;

public class HelloWorldSpring {

public static void main(String[] args) {

// TODO Auto-generated method stub

        ApplicationContext ctx = new FileSystemXmlApplicationContext("src/helloWorldSpring.xml");

        HelloWorldSpringBean helloWorldSpringBean = (HelloWorldSpringBean)ctx.getBean("myHelloWorld");

        helloWorldSpringBean.show();

    }

}

-----------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="myHelloWorld" class="chapter2.HelloWorldSpring.HelloWorldSpringBean">

<property name="hello">

<value>hello World spring!</value>

</property>

</bean>

</beans>
      

spring原理 实践解析-简单的helloworld

spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包

spring原理案例-基本项目搭建 02 spring jar包详解 spring jar包的用途

spring原理案例-基本项目搭建 03 创建工程运行测试 spring ioc原理实例示例

springmvc整合mybatis完整项目示例

springmvc 项目完整示例01 需求与数据库表设计 简单的springmvc应用实例 web项目

springmvc 项目完整示例02 项目创建-eclipse创建动态web项目 配置文件 junit单元测试

springmvc 项目完整示例03 小结

springmvc 项目完整示例04 整合mybatis mybatis所需要的jar包 mybatis配置文件 sql语句 mybatis应用

springmvc 项目完整示例05  日志 --log4j整合 配置 log4j属性设置 log4j 配置文件 log4j应用

springmvc 项目完整示例06 日志–log4j 参数详细解析 log4j如何配置

springmvc 项目完整示例07 设置配置整合springmvc springmvc所需jar包springmvc web.xml文件配置

springmvc 项目完整示例08 前台页面以及知识点总结

maven项目整合springmvc整合mybatis

eclipse 创建maven 项目 动态web工程完整示例

eclipse 创建maven 项目 动态web工程完整示例 maven 整合springmvc整合

spring原理案例-基本项目搭建 03 创建工程运行测试 spring ioc原理实例示例的更多相关文章

  1. spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包

    下载spring http://spring.io/ 最重要是在特征下面的这段话,需要注意: All avaible features and modules are described in the ...

  2. spring原理案例-基本项目搭建 02 spring jar包详解 spring jar包的用途

    Spring4 Jar包详解 SpringJava Spring AOP: Spring的面向切面编程,提供AOP(面向切面编程)的实现 Spring Aspects: Spring提供的对Aspec ...

  3. 【spring colud】spring cloud微服务项目搭建【spring boot2.0】

    spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...

  4. 基于maven+dubbo+spring+zookeeper的简单项目搭建

    maven下搭建dubbo小demo,供初学者学习,有不正确地方还请见谅. 先推荐一篇创建maven项目的文章,个人认为比较完整详细清楚: http://www.cnblogs.com/leiOOle ...

  5. freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建

    今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...

  6. 【Spring Cloud】实战项目搭建

    0.项目搭建 创建maven项目,删除其中的src目录,作为整体父项目,在其中添加module实现各个组件. 1.Eureka Server的实现 添加module,创建Spring Boot项目,添 ...

  7. 一 、Spring Boot 学习之项目搭建

    一.简介 spring 官方网站本身使用Spring 框架开发,随着功能以及业务逻辑的日益复杂,应用伴随着大量的XML配置文件以及复杂的Bean依赖关系. 随着Spring 3.0的发布,Spring ...

  8. 【Android】cocos2d-x-3.1.1环境搭建与创建工程( Win7 32位系统)

    参考资料: http://blog.csdn.net/wxc237786026/article/details/32907079 1.环境搭建 2.创建工程 2.1 VS2012运行 2.2 Andr ...

  9. 从零一起学Spring Boot之LayIM项目长成记(四) Spring Boot JPA 深入了解

    前言 本篇内容主要是一些关于JPA的常用的一些用法等.内容也是很多是看其他博客学来的,顺道在本系列博客里抽出一篇作为总结.下面让我们来看看吧. 不过我更推荐大家读本篇:https://lufficc. ...

随机推荐

  1. Java中死锁的定位与修复

    死锁应该可以说是并发编程中比较常见的一种情况,可以说如果程序产生了死锁那将会对程序带来致命的影响:所以排查定位.修复死锁至关重要: 我们都知道死锁是由于多个对象或多个线程之间相互需要对方锁持有的锁而又 ...

  2. LeetCode 33 Search in Rotated Sorted Array [binary search] <c++>

    LeetCode 33 Search in Rotated Sorted Array [binary search] <c++> 给出排序好的一维无重复元素的数组,随机取一个位置断开,把前 ...

  3. 小米 OJ 编程比赛 01 月常规赛_灯_找规律

     灯 序号:#125难度:有挑战时间限制:1000ms内存限制:32M 描述 一个屋子有 n 个开关控制着 n 盏灯,但奇怪的是,每个开关对应的不是一盏灯,而是 n-1 盏灯,每次按下这个开关,其对应 ...

  4. jstl使用中的错误----基于idea

    第一:首先正确将jstl.jar和standard.jar导入项目的lib目录下,注意两者的版本信息 第二: <%@ taglib prefix="c" uri=" ...

  5. [译文]Domain Driven Design Reference(六)—— 提炼战略设计

    本书是Eric Evans对他自己写的<领域驱动设计-软件核心复杂性应对之道>的一本字典式的参考书,可用于快速查找<领域驱动设计>中的诸多概念及其简明解释. 其它本系列其它文章 ...

  6. 在ASP.NET Core中使用brotli压缩

    Brotli是一种全新的数据格式,可以提供比Zopfli高20-26%的压缩比.据谷歌研究,Brotli压缩速度同zlib的Deflate实现大致相同,而在Canterbury语料库上的压缩密度比LZ ...

  7. C#的几种文件操作方法

    创建或覆盖文件 需求:如果文件不存在,创建之,如果存在,覆盖之. 1,可能有问题的方法 using (FileStream fs = File.OpenWrite(@"d:\work\1.t ...

  8. Vue 单文件元件 — vTabs

    简书原文 这是我做了第二个单文件元件 第一个在这里vCheckBox 这次这个叫vTabs,用于操作标签页 演示DEMO 演示DEMO2 - 子组件模式及别名 演示DEMO3 - 极简模式 示例: h ...

  9. Html5视频播放器-VideoJS+Audio标签实现视频,音频及字幕同步播放

    一,VideoJS介绍 引用脚本,videojs很为你着想,直接cdn了,你都不需要下载这些代码放入自己的网站 <link href=”http://vjs.zencdn.net/c/video ...

  10. Python微信公众号开发—小白篇

    本文面向想通过Python学习公众号开发的同学.一站式解决新手开发微信公众号遇到的所有问题. 为了防止我的文章被到处转载,贴一下我的公众号[智能制造专栏],欢迎大家关注. github仓库地址http ...