膜拜阿里架构师全程手写Spring MVC https://blog.csdn.net/gupao123456/article/details/84573462
Spring报错java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.getMethod(Ljava/lang/Class; https://blog.csdn.net/coffeesweet/article/details/52336291
JAVA 框架 / SPRING / SPRING系列教材 (三)- 注解方式 IOC/DI Spring系列教材 (三)- 注解方式 IOC/DI
spring源码分析(三)——注解为属性赋值 https://blog.csdn.net/pzq915981048/article/details/84000427
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Spring | Leading Recruitment in IT Jobs Across the UK</groupId>
<artifactId>spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring</name>
<!-- FIXME change it to the project's website -->
<url>Example Domain</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-cas</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see Plugin Bindings for Default Lifecycle Reference -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
########
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="Index of /schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="Index of /schema/aop"
xmlns:tx="Index of /schema/tx" xmlns:context="Index of /schema/context"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
Index of /schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="www.spring.com.spring" />
<aop:aspectj-autoproxy />
</beans>
############
Source.java
package www.spring.com.spring;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("Source")
public class Source
{
@Value("apple")
private String fruit; // 类型
@Value("10")
private String sugar; // 糖分描述
@Value("max")
private String size; // 大小杯
public String getFruit()
{
return fruit;
}
@Override
public String toString()
{
return "Source [fruit=" + fruit + ", sugar=" + sugar + ", size=" + size + "]";
}
public void setFruit(String fruit)
{
this.fruit = fruit;
}
public String getSugar()
{
return sugar;
}
public void setSugar(String sugar)
{
this.sugar = sugar;
}
public String getSize()
{
return size;
}
public void setSize(String size)
{
this.size = size;
}
}
#########
Test.java
package www.spring.com.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Test
{
public static void main(String[] args)
{
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
Source source = (Source)context.getBean("Source");
System.out.println(source);
}
}
###########
JuiceMaker.javaJuiceMaker.javapackage www.spring.com.spring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("JuiceMaker")
public class JuiceMaker
{
// 唯一关联了一个 Source 对象
@Autowired
private Source source;
public void makeJuice()
{
String juice = "xxx用户点了一杯" + source.getFruit() + ":" + source.getSugar() + ":" + source.getSize();
System.out.println(juice);
}
public Source getSource()
{
return source;
}
public void setSource(Source source)
{
this.source = source;
}
@Override
public String toString()
{
return "JuiceMaker [source=" + source + "]";
}
}
###########
Test.javaTest.javapackage www.spring.com.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Test
{
public static void main(String[] args)
{
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
JuiceMaker juiceMaker = (JuiceMaker)context.getBean("JuiceMaker");
juiceMaker.makeJuice();
}
}
#############
ProductService.java
package www.spring.com.spring;
import org.springframework.stereotype.Component;
@Component("ProductService")
public class ProductService
{
public void doSomeService()
{
System.out.println("Main doSomeService");
}
}
##########
LoggerAspect.javaLoggerAspect.javapackage www.spring.com.spring;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component("LoggerAspect")
public class LoggerAspect
{
@Around(value = "execution(* www.spring.com.spring.ProductService.*(..))")
public Object log(ProceedingJoinPoint joinPoint)
throws Throwable
{
System.out.println("start log:" + joinPoint.getSignature().getName());
Object object = joinPoint.proceed();
System.out.println("end log:" + joinPoint.getSignature().getName());
return object;
}
}
############
Test.javaTest.javapackage www.spring.com.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Test
{
public static void main(String[] args)
{
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
ProductService productService = (ProductService)context.getBean("ProductService");
productService.doSomeService();
}
}
##########