栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

在IDEA中使用Maven依赖建立Spring框架

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在IDEA中使用Maven依赖建立Spring框架

pom.xml




  4.0.0

  org.example
  Spring01
  1.0-SNAPSHOT

  Spring01
  
  http://www.example.com

  
    UTF-8
    1.8
    1.8
  

  
    
      junit
      junit
      4.12
      test
    
    
      org.springframework
      spring-context
      5.2.4.RELEASE
    
      
          org.junit.jupiter
          junit-jupiter
          RELEASE
          compile
      
    
      junit
      junit
      4.13.2
    
  

  
    
      
        org.eclipse.jetty
        jetty-maven-plugin
        9.4.15.v20190215

      
    

  


spring.xml




    
        
        
        
    

目录卡结构:

 User.java类


    package com.cx.bean;

    public class User {
        private Integer id;
        private String username;
        private String password;

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public User() {
        }

        public User(Integer id, String username, String password) {
            this.id = id;
            this.username = username;
            this.password = password;
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    ", username='" + username + ''' +
                    ", password='" + password + ''' +
                    '}';
        }
    }

测试类:

package com.cx.test;

import com.cx.bean.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserTest {
    @Test
    public void userTest() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        User user = (User)applicationContext.getBean("user");
        System.out.println(user);
    }
}

巡行截图:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/933363.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号