使用Intellij编写Spring Hello World
编写基于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的更多相关文章
- 【Spring Boot&&Spring Cloud系列】使用Intellij构建Spring Boot和Mybatis项目
一.创建项目 1.File->New->Project->spring initializer 2.勾选Web SQL Template Engines 3.项目生成之后,点击add ...
- [error] eclipse编写spring等xml配置文件时只有部分提示,tx无提示
eclipse编写spring等xml配置文件时只有<bean>.<context>等有提示,其他标签都没有提示 这时就需要做以下两步操作(下面以事务管理标签为例) 1,添加命 ...
- 框架:Intellij搭建Spring框架
第二章.Intellij搭建Spring框架 前提条件:jdk.jre已经安装完成 方法一.intellij下载jar 附:自带的jar的版本为4.3[2018/11/22] 第一步:选择File&g ...
- Intellij IDEA Spring Boot 项目Debug模式启动缓慢问题
问题 Intellij IDEA Spring Boot 项目Debug模式启动缓慢 环境 os: windows10 idea :2018.1 解决方法 去除所有断点就正常了,很诡异,原因未知.
- (转)编写Spring的第一个案例并测试Spring的开发环境
http://blog.csdn.net/yerenyuan_pku/article/details/52832145 Spring4.2.5的开发环境搭建好了之后,我们来编写Spring的第一个案例 ...
- (转)在编写Spring框架的配置文件时,标签无提示符的解决办法
http://blog.csdn.net/yerenyuan_pku/article/details/52831618 问题描述 初学者在学习Spring框架的过程中,大概会碰到这样一个问题:在编写S ...
- 如何使用VS Code编写Spring Boot (第二弹)
本篇文章是续<如何使用VS Code编写Spring Boot> 之后,结合自己.net经验捣鼓的小demo,一个简单的CRUD,对于习惯了VS操作模式的.net人员非常方便,强大的智能提 ...
- 换一种方式编写 Spring MVC 接口
1. 前言 通常我们编写 Spring MVC 接口的范式是这样的: @RestController @RequestMapping("/v1/userinfo") public ...
- 编写spring配置文件时,不能出现帮助信息
由于spring的schema文件位于网络上,如果机器不能连接到网络,那么在编写配置信息时候就无法出现提示信息,解决方法有两种: 1.让机器上网,eclipse会自动从网络上下载schema文件并缓存 ...
随机推荐
- 从桌面到 Web -- 领域模型
让我们暂时告别一下 ASP.NET Core 先介绍一下这个虚拟项目.因为我的主要目的是通过一个项目,全面学习一下 ASP.NET Core,所以这个项目时一个很简单的,不具备实际应用价值的虚拟项目, ...
- [Linux实践] macOS平台Homebrew更新brew update卡死,完美解决
[Linux实践] macOS 平台 Homebrew 更新 brew update 卡死,完美解决 版本2020.01.05 摘要: 使用brew install [软件包]安装软件包时,卡在Upd ...
- windows下使用cmd命令杀死进程
tasklist 使用以上命令显示当前进程,及其PID等,如图所示 找到我要删除的进程的pid(好像有点费劲?) 出现以下提示 原因:没有管理员权限,使用管理员模式打开 在Windows菜单栏中找到命 ...
- Don’t Repeat Yourself,Repeat Yourself
Don't Repeat Yourself,Repeat Yourself Don't repeat yourself (DRY, or sometimes do not repeat yoursel ...
- Jaeger容器化部署
概述 Jaeger是由Uber开源的分布式追踪系统,一套完整的Jager追踪系统包括Jaeger-client.Jaeger-agent.Jaeger-collector.Database和Jaege ...
- 序列积第m小元素 二分答案优化
给出两个长度为n的数组A和B, 在A和B中各任取一个, 可以得到n×n个积. 求第m小的元素. n<=100000 这一道题的意思就是 a1 a2 a3 a4.. b1 b2 b3 b4 n^2 ...
- redis简单操作
一.redis 基础操作 1.1.string 类型及操作 string 是最简单的类型,一个key对应一个value,string类型是二进制安全的.redis的string可以包含任何数据. 1. ...
- floyd + 最大流 (奶牛分配问题)
FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 &l ...
- 切蛋糕(贪心 or 优先队列)
链接:https://www.nowcoder.com/acm/contest/80/D来源:牛客网 最可爱的applese生日啦,他准备了许多个质量不同的蛋糕,想请一些同学来参加他的派对为他庆生,为 ...
- spark和mapreduce的区别
spark和mapreduced 的区别map的时候处理的时候要落地磁盘 每一步都会落地磁盘 reduced端去拉去的话 基于磁盘的迭代spark是直接再内存中进行处理 dag 执行引擎是一个job的 ...