官网
https://docs.spring.io/spring-framework/docs/5.2.0.RELEASE/spring-framework-reference/core.html#spring-core
https://maven.springframework.org/release/org/springframework/spring/4.3.9.RELEASE/ 以4.3.9版本为例(spring-framework-4.3.9.RELEASE-dist.zip)
开发spring至少需要使用的jar(5个+1个):spring-aop. jar开发AOP特性时需要的JARspring-beans. jar处理Bean的jarspring-context. jar处理spring_上下文的jarspring-core. jarspring核心jarspring- expression. jarspring表达式三方提供的日志jarcommons- logging. jar日志或者直接一个spring-webmvc
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.0.RELEASE</version> </dependency>(services.xml)配置文件👇 实际上就是上面get,如果把get方法删除则会报错 创建bean就相当于new了一个对象,默认调用无参
<?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 https://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- services --> <!--使用Spring创建对象,在Spring中称为Bean 类型 变量名 = new 类型(); HeLlo hello = new Hello(); id = 变量名 class = new的对象; . property 相当于给对象中的属性设置一个值! --> <bean id="petStore" class="org.springframework.samples.jpetstore.services.PetStoreServiceImpl"> <property name="accountDao" ref="accountDao"/> <property name="itemDao" ref="itemDao"/> <!-- additional collaborators and configuration for this bean go here --> </bean> <!-- more bean definitions for services go here --> </beans>不再需要new
public class MyTest { public static void main(String[] args) { //获取spring的上下文对象 ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); Hello hello = (Hello) context.getBean("hello"); System.out.println(hello.toString()); } }UserDao 👉 UserDaoImpl 👉 UserService 👉 UserServiceImpl 👉 main
-------------👉MysqlDaoImpl👉 UserService 👉 UserServiceImpl 👉 main
必须修改UserService
用户增加需求模块,不需改修改底层代码
有了别名,用别名也能调用
一般用于团队开发,将多个配置文件导入合并成一个
