java - How to dependency inject runtime arguments from static main method -
i have cucumber jvm + selenium scripts. main method this,
public static void main (string args[]) { environment.environmentvalue = args[0]; path.pathvalue = args[1]; username.superuser = args[2]; returncode = main.run( new string[] { "-g", "com.sanity.step.definition","-t", "@" +path , featurefile.replace("\\", "\\\\") }, separateclassloadertestrunner.class.getclassloader()); }
i have constructor class, i.e
public class cucumberrunner; private classutility environment; private classutility pathval; private classutility username; public cucumberrunner(classutility environment , classutility pathval, classutility username) { this.environment = environment; this.pathval=pathval; this.username= username; }
this classutility class,
public class classutility { public string environmentvalue; public string pathvalue; public string superuser; }
i getting compilation error "cannot make static reference non-static field method in main method "enviornment.environmentvalue = args[0]". how dependency injection static variables? can dependency injection runtime arguments?
spring boot can handle jvm arguments you.
you can inject parameters vm arguments when launching spring boot app.
for example, java -jar yourboot.jar -dargumentname=test
. can retrieve value doing : @value("${argumentname}") private string var
in spring beans (controllers, services, ...).
Comments
Post a Comment