SpringBootInputFiles by RAGHU
SpringBootInputFiles by RAGHU
=> Coming to Spring boot, it takes care of Define Spring Configuration code
(AutoConfiguration)
But here, programmer you need to provide inputs
-----------------------------------------------
https://docs.spring.io/spring-boot/docs/current/reference/html
/appendix-application-properties.html#transaction-properties
--------------------------------------------------------------
** To load properties file into Spring container code in Spring f/w
@PropertySource("classpath:application.properties").
In Spring boot also same code but written by boot only.
---------------------------------------------------------------
Note:
a. all keys must be placed inside application.properties which is under
src/main/resources(classpath)
b. key is String type, value can be any type like int/double/string/boolean..etc
c. Properties file is loaded by using code like:
@PropertySource("classpath:application.properties") by Spring boot only.
------code-----------------------
application.properties
#Hello from properties
app.title=SAMPLE ONE
app.version=1.0
2|Page
-by RAGHU SIR, NARESH IT, AMEERPET, HYD.
app.active=true
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class InputReadRunner
implements CommandLineRunner
{
//@Value("${key}")
@Value("${app.title}")
private String ttle;
@Value("${app.version}")
private double ver;
@Value("${app.active}")
private boolean active;
@Override
public void run(String... args) throws Exception {
System.out.println("from runner: " + ttle +"-
"+ver+"-"+active);
}
}
3|Page