简体   繁体   中英

how to use StandardEnvironment in a plan java application ,not in spring

When I read spring source code,I find the class StandardEnvironment. I want to use StandardEnvironment in a plan java application as follows。 But It is wrong. Can you help me?

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test], {ExactMatcher:fDisplayName=test(com.dominos.cloud.user.dao.EnvimentTest)], {LeadingIdentifierMatcher:fClassName=com.dominos.cloud.user.dao.EnvimentTest,fLeadingIdentifier=test]] from org.junit.internal.requests.ClassRequest@2acf57e3 at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:83) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:74) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49) at org.Z6B7B655DD22FAA3F1 0677C512493A8A0Z.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

public class EnvimentTest {


    @Test
    public void test() {

         StandardEnvironment enviment=new StandardEnvironment();
                System.out.println(enviment.getProperty("Pk")==null?"not value":enviment.getProperty("Pk"));


    }
}

You can not use StandartEnvironment without having Spring, it is part of spring.

What are you actually trying to achieve? Are you trying to use some kind of properties in a plain java application? What about usingjava.lang.System and its method getProperty? Do you think you can pass the needed arguments on startup of the java? ...like adding -DmyProperty=propertyValue

Another way that might be useful for you to look at is java.lang.Properties . You can create a properties object and load the data from an InputStream (for example from file).

If you need to support different sets of the properties for different runs of your java plain app, then you can combine both approaches and give as a system parameter the name of the file from where all the properties needs to be read.

Was this helpful to you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM