当前位置: 首页 > news >正文

maven搭建spring项目

前提

安装jdk
安装maven
安装eclipse

创建maven项目

在这里插入图片描述
在这里插入图片描述

搭建spring项目

pom.xml

<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.4.RELEASE</version>
</dependency>

新建hellospring.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

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

<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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><bean id="helloSpring"class="com.wujialiang.springstu01.HelloSpring"><property name="userName" value="李四"></property></bean>
</beans>

运行项目
在这里插入图片描述

http://www.lryc.cn/news/154364.html

相关文章:

  • Java“牵手”阿里巴巴商品详情数据,阿里巴巴商品详情API接口,阿里巴巴国际站API接口申请指南
  • MYSQL调优之思路----sql语句和索引调优
  • 论文阅读_变分自编码器_VAE
  • springboot整合elasticsearch使用案例
  • Unity制作下雨中的地面效果
  • windows从0搭建python3开发环境与开发工具
  • centos中得一些命令 记录
  • Python实现Word、Excel、PPT批量转为PDF
  • LLM大模型推理加速 vLLM
  • Python|小游戏之猫捉老鼠!!!
  • 万里路,咫尺间:汽车与芯片的智能之遇
  • Ubuntu22.04.1上 mosquitto安装及mosquitto-auth-plug 认证插件配置
  • CCKS2023:基于企业数仓和大语言模型构建面向场景的智能应用
  • LeetCode 热题 100——无重复字符的最长子串(滑动窗口)
  • 【zookeeper】zookeeper的shell操作
  • R语言Meta分析核心技术
  • Oracle数据库尚硅谷学习笔记
  • CG MAGIC进行实体渲染后!分析渲染器CR和VR的区别之处!
  • Ubuntu下Python3与Python2相互切换
  • 【深度学习】实验07 使用TensorFlow完成逻辑回归
  • 2023-09-04 Linux 让shell编译脚本里面设置的环境变量改变kernel里面驱动文件的宏定义值方法,我这里用来做修改固件版本
  • Python操作Excel实战:Excel行转列
  • java实现迭代器模式
  • C++day7模板、异常、auto关键字、lambda表达式、数据类型转换、STL、list、文件操作
  • 【校招VIP】产品分析之活动策划宣传
  • node基础之一:fs 模块
  • 如何快速搭建母婴行业的微信小程序?
  • 【科普向】Jmeter 如何测试接口保姆式教程
  • 阿里云2核4G服务器5M带宽5年费用价格明细表
  • 【图解RabbitMQ-2】图解JMS规范与AMQP协议是什么