菜鸟重学Spring

构建一个spring项目

1、创建一个工程,导入spring 所需的jar包

commons-logging-1.1.1

spring-aop-4.1.6.RELEASE

spring-aspects-4.1.6.RELEASE

spring-beans-4.1.6.RELEASE

spring-context-4.1.6.RELEASE

spring-context-support-4.1.6.RELEASE

spring-core-4.1.6.RELEASE

spring-expression-4.1.6.RELEASE

spring-instrument-4.1.6.RELEASE

spring-instrument-tomcat-4.1.6.RELEASE

spring-jdbc-4.1.6.RELEASE

spring-jms-4.1.6.RELEASE

spring-messaging-4.1.6.RELEASE

spring-orm-4.1.6.RELEASE

spring-oxm-4.1.6.RELEASE

spring-test-4.1.6.RELEASE

spring-tx-4.1.6.RELEASE

spring-web-4.1.6.RELEASE

spring-webmvc-4.1.6.RELEASE

spring-webmvc-portlet-4.1.6.RELEASE

spring-websocket-4.1.6.RELEASE

2、新建实体类

3、新建applicationContext.xml文件,配置bean

<?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-3.0.xsd">

   <bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
       <property name="message" value="Hello World!"/>
   </bean>

</beans>

4、编写测试类,调用ApplicationText接口对象获取bean

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext context = 
             new ClassPathXmlApplicationContext("Beans.xml");
      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
      obj.getMessage();
   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
1. 了解 Spring 的基础知识:学习 Spring 的前置条件是必须掌握 Java 编程语言的基础知识和面向对象编程思想。在学习 Spring 之前,建议先了解 Spring 的基本概念和原理,例如 IoC、AOP、Bean 等等。 2. 学习 Spring 官方文档:官方文档是学习 Spring 的最好资料之一,可以从官网上下载最新版本的文档或者在线阅读。在学习时,可以根据自己的需要分别阅读关于 Spring 框架的概述、Spring 核心、Spring MVC、Spring Boot 等模块的文档。 3. 参考优秀的 Spring 教程:有很多优秀的 Spring 教程可以参考,例如《Spring 实战》、《深入浅出 Spring Boot 2.x》等等。这些教程结合实际案例,可以更加生动形象地帮助学习者理解 Spring 的概念和使用方法。 4. 实践练习:学习 Spring 最好的方法就是通过实践来掌握它。可以通过搭建一个简单的 Spring 项目来实践,例如搭建一个基于 Spring MVC 的 Web 应用程序,或者使用 Spring Boot 搭建一个 RESTful API 服务。 5. 参加 Spring 相关的培训和课程:有很多机构提供 Spring 的培训和课程,可以选择适合自己的课程进行学习。这些课程通常会提供更加深入的理论知识和实践案例,可以帮助学习者更快、更全面地掌握 Spring。 6. 参加 Spring 相关的社区和论坛:可以在 Spring 官方论坛或者其他社区上参与讨论,与其他开发者交流经验和问题解决方案。这样可以加深对 Spring 的理解,同时也能够扩展自己的人脉和资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值