简体   繁体   English

如何在计划 java 应用程序中使用 StandardEnvironment,而不是在 spring 中

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

When I read spring source code,I find the class StandardEnvironment.当我阅读 spring 源代码时,我发现 class 标准环境。 I want to use StandardEnvironment in a plan java application as follows。 But It is wrong.我想在一个计划 java 应用程序中使用 StandardEnvironment,如下所示。但它是错误的。 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 java.lang.Exception: 没有找到匹配的测试 [{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) 在 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) 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.没有 Spring 就不能使用StandartEnvironment ,它是 spring 的一部分。

What are you actually trying to achieve?你到底想达到什么目的? Are you trying to use some kind of properties in a plain java application?您是否尝试在普通的 java 应用程序中使用某种属性? What about usingjava.lang.System and its method getProperty?使用java.lang.System及其方法 getProperty 怎么样? Do you think you can pass the needed arguments on startup of the java?您认为在 java 启动时可以通过所需的 arguments 吗? ...like adding -DmyProperty=propertyValue ...就像添加 -DmyProperty=propertyValue

Another way that might be useful for you to look at is java.lang.Properties .另一种可能对您有用的方法是java.lang.Properties You can create a properties object and load the data from an InputStream (for example from file).您可以创建属性 object 并从 InputStream 加载数据(例如从文件)。

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.如果您需要为 java 普通应用程序的不同运行支持不同的属性集,那么您可以将这两种方法结合起来,并将需要从中读取所有属性的文件名作为系统参数提供。

Was this helpful to you?这对您有帮助吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JDepend来识别Java Spring Maven应用程序中使用的库 - How to use JDepend to identify the libraries used in java spring maven application 如何在 Java 配置的 Spring 批处理应用程序中使用 DefaultJobParametersValidator? - How to use DefaultJobParametersValidator in Java-configured Spring Batch application? Java Spring-如何通过@WithUserDetails使用application.properties中的值 - Java Spring - How to use value from application.properties with @WithUserDetails 如何使用 Redis Cache 将数据存储在 java spring 启动应用程序中? - How to use Redis Cache to store the data in java spring boot application? JAVA Spring Rest API环境升级计划 - JAVA Spring Rest API environment upgrade plan 如何在spring boot 2中使用groovy解释(使用spring-aop注释)2使用maven构建java应用程序? - How to use groovy interpreted (with spring-aop annotation) within an spring boot 2 java application build with maven? Spring-如何使用Spring Dependency Injection编写独立的Java应用程序 - Spring- How to use Spring Dependency Injection to write a Standalone Java Application 在 Spring Boot 应用程序中使用 Java Websocket API - Use Java Websocket API in Spring Boot application 在Java应用程序中创建的代理中有多少使用Spring核心,Hibernate,Spring AOP? - How many proxies created in Java application use Spring core, Hibernate, Spring AOP? java spring:如何访问另一个Spring应用程序的应用程序上下文 - java spring: how to access Application Context of another Spring Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM