编写基于Intellij2016.3与Java SDK1.8

下载Spring最新jar包:

http://repo.spring.io/release/org/springframework/spring

和Spring依赖的日志组件包

http://commons.apache.org/proper/commons-logging/

1、新建一个Module

上图如果选择不完整的话,可以如下添加依赖添加确实的jar包。

2、添加依赖

经测试,一个简单的HelloWorld程序也需要依赖如下5个包:

3、编写测试文件

HelloWorld.java

package com.xiya;

/**
* Created by N3verL4nd on 2017/3/4.
*/
public class HelloWorld {
private String message; public void setMessage(String message) {
this.message = message;
} public String getMessage() {
return message;
}
}

MainApp.java

package com.xiya;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by N3verL4nd on 2017/3/4.
*/
public class MainApp {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
HelloWorld test = (HelloWorld) applicationContext.getBean("HelloWorld");
System.out.println(test.getMessage());
}
}

4、编写beans配置文件(src目录下)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="HelloWorld" class="com.xiya.HelloWorld">
<property name="message" value="Spring Hello World!" />
</bean>
</beans>

一下对程序运行并没有影响,它的作用估计是方便查找xml文件之间的关系吧

运行,报错:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:161)
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:225)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:88)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:58)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.xiya.MainApp.main(MainApp.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more Process finished with exit code 1

原因是少加入commons-logging-1.2包

添加方法同上。

测试:

使用Intellij编写Spring Hello World的更多相关文章

  1. 【Spring Boot&&Spring Cloud系列】使用Intellij构建Spring Boot和Mybatis项目

    一.创建项目 1.File->New->Project->spring initializer 2.勾选Web SQL Template Engines 3.项目生成之后,点击add ...

  2. [error] eclipse编写spring等xml配置文件时只有部分提示,tx无提示

    eclipse编写spring等xml配置文件时只有<bean>.<context>等有提示,其他标签都没有提示 这时就需要做以下两步操作(下面以事务管理标签为例) 1,添加命 ...

  3. 框架:Intellij搭建Spring框架

    第二章.Intellij搭建Spring框架 前提条件:jdk.jre已经安装完成 方法一.intellij下载jar 附:自带的jar的版本为4.3[2018/11/22] 第一步:选择File&g ...

  4. Intellij IDEA Spring Boot 项目Debug模式启动缓慢问题

    问题 Intellij IDEA Spring Boot 项目Debug模式启动缓慢 环境 os: windows10 idea :2018.1 解决方法 去除所有断点就正常了,很诡异,原因未知.

  5. (转)编写Spring的第一个案例并测试Spring的开发环境

    http://blog.csdn.net/yerenyuan_pku/article/details/52832145 Spring4.2.5的开发环境搭建好了之后,我们来编写Spring的第一个案例 ...

  6. (转)在编写Spring框架的配置文件时,标签无提示符的解决办法

    http://blog.csdn.net/yerenyuan_pku/article/details/52831618 问题描述 初学者在学习Spring框架的过程中,大概会碰到这样一个问题:在编写S ...

  7. 如何使用VS Code编写Spring Boot (第二弹)

    本篇文章是续<如何使用VS Code编写Spring Boot> 之后,结合自己.net经验捣鼓的小demo,一个简单的CRUD,对于习惯了VS操作模式的.net人员非常方便,强大的智能提 ...

  8. 换一种方式编写 Spring MVC 接口

    1. 前言 通常我们编写 Spring MVC 接口的范式是这样的: @RestController @RequestMapping("/v1/userinfo") public ...

  9. 编写spring配置文件时,不能出现帮助信息

    由于spring的schema文件位于网络上,如果机器不能连接到网络,那么在编写配置信息时候就无法出现提示信息,解决方法有两种: 1.让机器上网,eclipse会自动从网络上下载schema文件并缓存 ...

随机推荐

  1. 1023 组个最小数 (20 分)C语言

    给定数字 0-9 各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位).例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就 ...

  2. Qt5学习(1)

    1. In Qt, if you want to apply styles to the main window  itself, you must apply it to  its central ...

  3. Java虚拟机OOM问题和四大引用问题简述

    一.请你谈谈实际的项目中在Java虚拟机会抛出哪些异常,每个异常都是怎么产生的? 1.java.lang.StackOverflowError 栈空间满了 public static void sta ...

  4. 【转】在MyEclipse 8.6上搭建Android开发环境

    内容导航 第 1 页:基本环境准备 第 2 页:下载Android SDK 第 3 页:配置SDK环境变量 第 4 页:给MyEclipse安装ADT插件 第 5 页:配置MyEclipse 第 6 ...

  5. 三、Spring Cloud之软负载均衡 Ribbon

    前言 上一节我们已经学习了Eureka 注册中心,其实我们也使用到了Ribbon ,只是当时我们没有细讲,所以我们现在一起来学习一下Ribbon. 什么是Ribbon 之前接触到的负载均衡都是硬负载均 ...

  6. DevOps is Hard、DevSecOps is Even Harder . --- Enterprise Holdings

    Enterprise Holdings. 的IT团队超过2000人,在2018年的演讲中介绍了Enterprise Holdings的DevOps是如何转型的.我们通过打造一个不只包涵了pipelin ...

  7. python条件(三元)运算符

    条件运算符  是 三元运算符 语法: 语句1  if   条件表达式  else  语句2 执行流程: 条件运算符在执行时,会先对条件表达式进行求值判断         如果判断结果为True,则执行 ...

  8. 测试工具Fiddler(三)—— 常见功能介绍

    Fiddler的功能面板 1.statistics:请求的性能指标:全世界范围的性能测试: RTP:一个请求的从发送出去到返回的时间: Show chart可以看出图表的示例: 2.inspector ...

  9. 关于python列表的一些基础知识。

    因学校实验室要求,自学了python,一开始看书觉得太简单了,也没有多动手去尝试,直到看完了前八章突然想动手试试的时候,人傻了,深刻体会到了好记性不如烂笔头的道理,故整理一些python列表的操作. ...

  10. 20191102Java课堂记录

    1. import javax.swing.*; class AboutException { public static void main(String[] a) { int i=1, j=0, ...