1. package soundsystem; import org.springframework.beans.factory.annotation.Autowired; public class CDPlayer implements MediaPlayer { private CompactDisc cd; @Autowired public CDPlayer(CompactDisc cd) { this.cd = cd; } public void play() { cd.play();…
一.当构造函数有集合时,只能用<CONSTRUCTOR-ARG>,不能用C-NAMESPACE 二. 1. package soundsystem.collections; import java.util.List; import soundsystem.CompactDisc; public class BlankDisc implements CompactDisc { private String title; private String artist; private List&l…
一.在xml中引入xml,用<import> <?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:c="http://www.…
一.注入简单属性 package soundsystem.properties; import org.springframework.beans.factory.annotation.Autowired; import soundsystem.CompactDisc; import soundsystem.MediaPlayer; public class CDPlayer implements MediaPlayer { private CompactDisc compactDisc; @A…
1. package soundsystem; public class SgtPeppers implements CompactDisc { private String title = "Sgt. Pepper's Lonely Hearts Club Band"; private String artist = "The Beatles"; public void play() { System.out.println("Playing "…
spring的bean默认是单例,加载容器是会被化,spring会拦截其他再次请求bean的操作,返回spring已经创建好的bean. It appears that the CompactDisc is provided by calling sgtPeppers , but that’s notexactly true. Because the sgtPeppers() method is annotated with @Bean , Spring willintercept any ca…
1. package soundsystem; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class CDPlayerConfig { @Bean public CompactDisc compactDisc() { return new SgtPeppers(); }…
一.@ComponentScan 1. @Configuration //说明此类是配置文件 @ComponentScan //开启扫描,会扫描当前类的包及其子包 public class CDPlayerConfig { } 2. @ComponentScan(basePackages={"soundsystem", "video"})//扫描多个包 public class CDPlayerConfig { } 3. @ComponentScan(basePac…
1. package soundsystem; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration //说明此类是配置文件 //@ComponentScan //开启扫描,会扫描当前类的包及其子包 //@ComponentScan(basePackages={"soundsys…
1.把包含敏感信息的请求转为https请求,则较为安全,但如何只把有需要安全的请求转为https,而不是不加分辩就把所有请求都转为https呢?可以用requiresChannel() @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/spitter/me").hasRole("SPITTER&quo…