maven搭建spring项目

前提

安装jdk

安装maven

安装eclipse

创建maven项目


搭建spring项目

pom.xml

xml 复制代码
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-context</artifactId>
	<version>5.0.4.RELEASE</version>
</dependency>

新建hellospring.java

java 复制代码
package com.wujialiang.springstu01;

public class HelloSpring {
	private String userName;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public void show() {
		System.out.println(userName+" 你好");
	}
}

修改App.java

java 复制代码
package com.wujialiang.springstu01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	ApplicationContext ctx =new 
    			ClassPathXmlApplicationContext("applicationContext.xml");
        HelloSpring hello =(HelloSpring)ctx.getBean("helloSpring");
        hello.show();
    }
}

main下新建resources文件夹,该文件下新建applicationContext.xml

xml 复制代码
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	   http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
	<bean id="helloSpring"
		class="com.wujialiang.springstu01.HelloSpring">
		<property name="userName" value="李四"></property>
	</bean>
</beans>

运行项目

相关推荐
野生技术架构师2 小时前
2026 Java 面试全套总结,八股 + 场景 + AI 相关面试考点
java·人工智能·面试
香吧香2 小时前
java服务异常日志只打印异常类型,没有堆栈定位分析
java·jvm·异常
qq_2518364573 小时前
AI 疾病自查功能SpringbootAI项目实战 · 技术实现文档
java·ai·ai编程
逆境不可逃3 小时前
Pi Agent 学习笔记:对话太长以后,如何压缩上下文
java
MetaLite3 小时前
JDK 8~26 核心特性一览:从 Stream 到 Scoped Values
java
wno7044 小时前
Spring Boot WebFlux增删改查
java·spring boot·后端
君顾14 小时前
上海24小时自助健身房系统开发实战指南:从架构设计到落地部署
java·开发语言·健身房
SL_staff5 小时前
别急着买商业规则引擎:90%风控场景根本不需要全量编码能力
java·程序员·groovy
ManageEngineITSM5 小时前
DevOps和ITIL是什么关系?是替代还是互补一文讲清
java·服务器·资产管理·变更管理
SL_staff6 小时前
ERP排程总在纸上谈兵?JVS-APS如何用真实产能约束打通计划与执行闭环
java·人工智能·开源