spring 完结

This commit is contained in:
法然
2022-10-14 23:39:59 +08:00
parent b91ab7307e
commit 24bc4f24fe
265 changed files with 7316 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
/**
* @author yinkanglong
* @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $
*/
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--开启组件扫描
1. 如果扫描多个包,多个包之间使用逗号隔开
2. 扫描包的上层目录-->
<context:component-scan base-package="com.ykl"></context:component-scan>
</beans>

View File

@@ -0,0 +1,19 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.ykl.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
/**
* @author yinkanglong
* @version : SpringConfig, v 0.1 2022-10-09 13:18 yinkanglong Exp $
*/
@Configuration
@ComponentScan(basePackages = {"com.ykl"})
public class SpringConfig {
}

View File

@@ -0,0 +1,13 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.ykl.dao;
/**
* @author yinkanglong
* @version : UserDo, v 0.1 2022-10-09 12:03 yinkanglong Exp $
*/
public interface UserDo {
public void add();
}

View File

@@ -0,0 +1,19 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.ykl.dao;
import org.springframework.stereotype.Repository;
/**
* @author yinkanglong
* @version : UserDoImpl, v 0.1 2022-10-09 12:04 yinkanglong Exp $
*/
@Repository
public class UserDoImpl implements UserDo{
@Override
public void add() {
System.out.println("dao add ... ...");
}
}

View File

@@ -0,0 +1,28 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.ykl.service;
import com.ykl.dao.UserDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* 与xml配置等价value值可以省略不写
* 默认值是类名称,首字母小写。
*/
@Service
public class UserService {
@Autowired
@Qualifier(value = "userDoImpl")
private UserDo userDo;
public void add(){
System.out.println("service add ... ...");
userDo.add();
}
}

View File

@@ -0,0 +1,36 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.ykl.test;
import com.ykl.config.SpringConfig;
import com.ykl.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author yinkanglong
* @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $
*/
public class Test01 {
@Test
public void testService(){
ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml");
UserService userService = context.getBean("userService", UserService.class);
userService.add();
}
@Test
public void testConfig(){
//加载配置类
ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
UserService userService = context.getBean("userService", UserService.class);
userService.add();
}
}

View File

@@ -0,0 +1,4 @@
prop.driverClass=com.mysql.jdbc.Driver
prop.url=jdbc:mysql://localhost:3306/user
prop.username=root
prop.password=123456