编写基于Intellij2016.3与Java SDK1.8
下载Spring最新jar包:
http://repo.spring.io/release/org/springframework/spring
http://commons.apache.org/proper/commons-logging/
1、新建一个Module
上图如果选择不完整的话,可以如下添加依赖添加确实的jar包。
2、添加依赖
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>
运行,报错:
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包
添加方法同上。
测试:
分享到:
相关推荐
spring mvc 在 intellij 的 helloworld 基本配置,以及简单的mvc资源映射
主要介绍了IntelliJ IDEA 创建spring boot 的Hello World 项目的步骤详解,需要的朋友可以参考下
IntelliJ IDEA 2017建立简单spring(hua).pdf,是我用spring写的简单的hello world
通过maven来配置spring mvc,开发工具为IntelliJ IDEA,服务器为tomcat,页面主要有一个hello world 页面和一个test页面
Spring Boot应用程序样本 该示例Spring Boot应用程序是为博客文章编写的,该博客文章描述了如何使用IntelliJ创建Spring Boot应用程序。
入门作业的源码,对于会的一点用都没有,只有还没咋接触过的人当作入门小源码用
[示例 Spring Boot 应用程序] ( ) 此示例 Spring Boot 应用程序是为一篇描述如何使用 IntelliJ 创建 Spring Boot 应用程序的博客文章编写的。 使用相关博文: :
helloworld|[spring mvc,Spring Boot项目创建,单元测试](https://github.com/smltq/spring-boot-demo/blob/master/helloworld/HELP.md) web|[ssh项目,spring mvc,过滤器,拦截器,监视器,thymeleaf,lombok,jquery,...
使用BeanPostProcessor的Hello World示例 3.7.1.2. RequiredAnnotationBeanPostProcessor示例 3.7.2. 用BeanFactoryPostProcessor定制配置元数据 3.7.2.1. PropertyPlaceholderConfigurer示例 3.7.2.2. ...
IntelliJ IDEA 2017建立简单springMVC(hua).pdf 这是我用springMVC写的简单的hello world
Topera的Hello World#005 使用SpringBoot的Rest Server 这个世界是使用SpringBoot创建的Rest Server(使用Gradle配置) 如何下载此源代码 安装 使用获取该存储库URL上方的Clone or download按钮 在IntelliJ IDEA...
下载后里面的target目录下有war包,可以直接放在tomcat下运行。...项目使用Intellij Idea 14 创建。 http://localhost:8080/rest/helloWorld/a 单独的jersey http://localhost:8080/rest/demo/hello 集成spring的jersey
Jetty和Maven HelloWorld教程 Jetty(6)入门 (www.itjungle.com) Jetty Start.jar 配置Jetty 如何设置上下文(Context Path) 如何知道使用了那些jar包 如何配置SSL 如何使用非root用户监听80端口 如何配置连接器...
将网站跑起来,能在网页上看到"Hello World" 使用JSP在页面上显示出用户的基本信息(静态信息),包括姓名、性别、邮箱、年龄。 提示: gradle启动jetty index.jsp(用最简单的方式实现第2问) 知识点: gradle运行...
你好休息使用 Spring 4 和 Gradle 的 Hello World 应用程序。 使用./gradlew eclipse项目加载到./gradlew eclipse 使用./gradlew idea项目加载到 Intellij 使用./gradlew tomcatRun在 tomcat 上运行
空手道初学者本入门指南显示了如何在IntelliJ , maven和gradle内设置基于SpringBoot的REST服务并使用Karate(0.9.6)对其进行测试。休息服务这是一个标准的Spring Boot应用程序,它公开了两个API你好API $ curl ...
Nginx配置文件详解Linux 安装JenkinsJAVA 多线程详解java 多线程学习How to create a Hello World with IntelliJ and Aspect JJava各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分Java finally...
最简单的春天引导你好世界 最简单的Spring Boot Hello World示例 脚步 git clone 从您最喜欢的IDE(Eclipse,IntelliJ,Netbeans)运行 享受你好世界的力量! 欢迎使用Spring Boot :)
API的编写 Ajax应用,angular框架,Bootstrap使用 数据库迁移的概念 gradle git ... 需求 实现用户管理系统,全程用git版本控制 第一阶段 将网站跑起来,能在网页上看到"Hello World" 使用JSP在页面上显示出用户的...
建立一个网关 建立一个网关 IDE:Intellij ...{ "args": {}, "headers": { "Accept": "*/*", "Accept-Encoding": "gzip, deflate", ... "Hello": "World", "Host": "httpbin.org", "Postman-Token": "91