Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Autowired in spring

/* Can be done in 3 ways */

/* As class properties or Field Injection*/
class A {
	
    @Autowired
	private DIInjectable depInj;
    
    public doSomething(){
     	this.depInj.initiate();
      	// Rest of the code
      	// ...
    }
  
  	...
}

/* In constructor - Constructor Injection*/
class A {
  
  	private DIInjectable depInj;
  	
  	@Autowired
  	public A(DIInjectable depInj){
      this.depInj = depInj;
    }
  
  	public doSomething(){
      this.depInj.initiate();
      // Rest of the code
      // ...
    }
  
  	...
}
    
/* Setter Injection*/
class A {
  
  	private DIInjectable depInj;
  	
	...
    
    @Autowired
	public void setDiInjectable(DIInjectable depinj){
      this.depInj = depInj;
    }
  
  
  	public doSomething(){
      this.depInj.initiate();
      // Rest of the code
      // ...
    }
  
  	...
}
Comment

PREVIOUS NEXT
Code Example
Java :: java length of array 
Java :: findview by id in android 
Java :: java find largest number in list 
Java :: identifier in java 
Java :: java lambda 
Java :: java character in string 
Java :: java android join array list 
Java :: how to delete last array in java 
Java :: find number of weeks between two dates in java 
Java :: java jcombobox selected item changed 
Java :: java printstacktrace 
Java :: java how to write something on the console with scanner 
Java :: a ^ b java 
Java :: how to stop screen going off android studio 
Java :: 1.13. programacion orientada a objetos en java 
Java :: jlabel icon size 
Java :: como limpar a tela do consola no java 
Java :: in java write a code that suppose the following input is supplied to the program: 9 Then, the output should be: 12096 (99+999+9999+999) 
Sql :: uninstall mysql ubuntu 18.04 
Sql :: find column in all stored procedures sql server 
Sql :: show size of all tables postgres 
Sql :: copy table oracle 
Sql :: oracle create table comment 
Sql :: copy table sql server 
Sql :: mysql database stopped xampp mac 
Sql :: sql server kill all connections 
Sql :: possgress drop if exists table 
Sql :: sql concate two columns first and last 
Sql :: mysql remove last character 
Sql :: mysql random limit 1 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =