news 2026/5/1 4:04:13

spring入门案例程序开发

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
spring入门案例程序开发

目录

  • 入门案例程序开发
  • 入门案例程序分析

入门案例程序开发

创建maven工程

创建子模块

引入spring相关依赖

<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>6.0.2</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.6.3</version></dependency></dependencies>

创建类,定义属性和方法

package com.baidu.spring6;public classUser{public voidadd(){System.out.println("add.............");}}

按照spring要求创建配置文件(xml格式)

在spring配置文件配置相关信息

<!--完成user对象的创建 bean标签 id属性:唯一标识 class属性:要创建对象所在类的全路径(包名称+类名称)--><bean id="user"class="com.baidu.spring6.User"></bean>

测试

package com.baidu.spring6;import org.junit.jupiter.api.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public classTestUser{@Test public voidtestUserObject(){// 加载Spring配置文件ApplicationContext context=newClassPathXmlApplicationContext("bean.xml");// 获取创建的对象User user=(User)context.getBean("user");System.out.println("user = "+user);// 使用对象调用方法进行测试user.add();}}

入门案例程序分析

使用这种方式创建对象的,无参数构造执行?

修改User

重新执行测试代码

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/1 2:05:19

Bullseye系统下树莓派摄像头无法启动?核心要点解析

Bullseye系统下树莓派摄像头无法启动&#xff1f;一文讲透底层机制与实战修复你是不是也遇到过这种情况&#xff1a;硬件接好了&#xff0c;排线插到底了&#xff0c;旧系统跑得好好的摄像头&#xff0c;在升级到最新的Raspberry Pi OS Bullseye后突然“失明”——libcamera-he…

作者头像 李华
网站建设 2026/5/1 2:04:08

OpenCPN 航海导航软件终极指南:从新手到高手的完整教程

OpenCPN 航海导航软件终极指南&#xff1a;从新手到高手的完整教程 【免费下载链接】OpenCPN A concise ChartPlotter/Navigator. A cross-platform ship-borne GUI application supporting * GPS/GPDS Postition Input * BSB Raster Chart Display * S57 Vector ENChart Displ…

作者头像 李华
网站建设 2026/5/1 3:05:57

终极指南:如何用whisper-large-v3-turbo实现8倍速语音转文字

终极指南&#xff1a;如何用whisper-large-v3-turbo实现8倍速语音转文字 【免费下载链接】whisper-large-v3-turbo 项目地址: https://ai.gitcode.com/hf_mirrors/openai/whisper-large-v3-turbo 还在为漫长的语音转文字等待时间而焦虑吗&#xff1f;每次处理会议录音、…

作者头像 李华
网站建设 2026/5/1 3:05:56

Android File Transfer Linux:跨平台文件传输终极解决方案

Android File Transfer Linux&#xff1a;跨平台文件传输终极解决方案 【免费下载链接】android-file-transfer-linux Android File Transfer for Linux 项目地址: https://gitcode.com/gh_mirrors/an/android-file-transfer-linux 还在为Linux系统与Android设备之间文件…

作者头像 李华
网站建设 2026/5/1 3:05:59

OptiScaler终极配置指南:5步快速掌握AI超分辨率技术

OptiScaler终极配置指南&#xff1a;5步快速掌握AI超分辨率技术 【免费下载链接】OptiScaler DLSS replacement for AMD/Intel/Nvidia cards with multiple upscalers (XeSS/FSR2/DLSS) 项目地址: https://gitcode.com/GitHub_Trending/op/OptiScaler 想要让老旧显卡也能…

作者头像 李华