1. 程式人生 > >Spring註入靜態service

Spring註入靜態service

bsp his spring () static control public pub pri

@Component
@Controller

public class Demo {


@Resource(name="userService")
private UserService userServiceTemp;

public UserService getUserServiceTemp() {
return userServiceTemp;
}

public void setUserServiceTemp(UserService userServiceTemp) {
this.userServiceTemp = userServiceTemp;
}

public static UserService userService;

@PostConstruct
public void init() {
userService = this.userServiceTemp;
}

}

原理

Spring註入靜態service