zoukankan      html  css  js  c++  java
  • Eclipse+Maven+Spring

    1.首先按照how2j教程搭建Maven项目:http://how2j.cn/k/maven/maven-eclipse-maven-project/1332.html

    2. 刚建好时没有资源文件夹的,需要自己添加

        -- 之前

          

        -- 添加

          项目右键 -> new -> Source Folder

          

        -- 之后

          

    3. 导入Spring依赖

       

        

        导入spring-context后,会自动导入其他Jar包(pom文件的dependency hierarchy视图)

        

        或者看工程目录中,maven dependencies

          

    4. 编写Bean

      -- 工程目录

        

      -- 代码

    package com.atguigu.spring_1;
    
    public class HelloBean {
    
        public void test() {
            System.out.println("hello, bean");
        }
    }

    5.利用springsource-tool-suite 这个插件构建 spring配置文件,很方便

      src/main/resources目录右键,新建

      

      

      

      一路Next,默认加载spring相关命名空间

      -- 编写xml文件(能体会到插件的好处,class自动提示全限定名!)

    <?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">
    
        <!-- 配置HelloBean -->
        <bean id="helloBean" class="com.atguigu.spring_1.HelloBean"></bean>
        
    </beans>

    5. 应用咯

      -- 工程目录图

        

      -- 代码

    package com.atguigu.spring_1;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class App 
    {
        public static void main( String[] args )
        {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
            
            HelloBean bean = (HelloBean)ctx.getBean("helloBean");
            
            bean.test();
        }
    }

    6. 结果

       

  • 相关阅读:
    敏捷实践-学习实践资料汇总
    从数据仓库到数据湖—浅谈数据架构演进
    JVM知识点汇总备忘
    Protobuf的使用和原理
    kafka数据定时导入hive便于后续做数据清洗
    Mybatis Mapper接口动态代理实现原理及二次开发
    软考论文-写作大纲-备考思路总结
    css3另一个属性写法
    css3动画效果
    jquery点击鼠标后关闭图片
  • 原文地址:https://www.cnblogs.com/heyboom/p/11349539.html
Copyright © 2011-2022 走看看