zoukankan      html  css  js  c++  java
  • 十四,SpringBoot读取配置文件application.properties

    方法1:Environment

        @Autowired//import org.springframework.core.env.Environment;
        private Environment environment;
    
        @org.junit.Test
        public void readConfigFile(){
            System.out.println(environment.getProperty("spring.datasource.driverClassName"));
        }

    控制台打印:

    "C:Program FilesJavajdk-11.0.7injava.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:IntelliJ IDEA 2019.1libidea_rt.jar=4872:E:IntelliJ IDEA 2019.1in" -Dfile.encoding=UTF-8 -classpath "E:IntelliJ IDEA 2019.1libidea_rt.jar;E:IntelliJ IDEA 2019.1pluginsjunitlibjunit-rt.jar;E:IntelliJ IDEA 2019.1pluginsjunitlibjunit5-rt.jar;D:学习代码javacleanSpringBoot	arget	est-classes;D:学习代码javacleanSpringBoot	argetclasses;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-web2.3.1.RELEASEspring-boot-starter-web-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter2.3.1.RELEASEspring-boot-starter-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-logging2.3.1.RELEASEspring-boot-starter-logging-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;F:apache-maven-3.6.0
    epositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;F:apache-maven-3.6.0
    epositoryorgapachelogginglog4jlog4j-to-slf4j2.13.3log4j-to-slf4j-2.13.3.jar;F:apache-maven-3.6.0
    epositoryorgapachelogginglog4jlog4j-api2.13.3log4j-api-2.13.3.jar;F:apache-maven-3.6.0
    epositoryorgslf4jjul-to-slf4j1.7.30jul-to-slf4j-1.7.30.jar;F:apache-maven-3.6.0
    epositoryjakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;F:apache-maven-3.6.0
    epositoryorgyamlsnakeyaml1.26snakeyaml-1.26.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-json2.3.1.RELEASEspring-boot-starter-json-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositorycomfasterxmljacksoncorejackson-databind2.11.0jackson-databind-2.11.0.jar;F:apache-maven-3.6.0
    epositorycomfasterxmljacksoncorejackson-annotations2.11.0jackson-annotations-2.11.0.jar;F:apache-maven-3.6.0
    epositorycomfasterxmljacksoncorejackson-core2.11.0jackson-core-2.11.0.jar;F:apache-maven-3.6.0
    epositorycomfasterxmljacksondatatypejackson-datatype-jdk82.11.0jackson-datatype-jdk8-2.11.0.jar;F:apache-maven-3.6.0
    epositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.11.0jackson-datatype-jsr310-2.11.0.jar;F:apache-maven-3.6.0
    epositorycomfasterxmljacksonmodulejackson-module-parameter-names2.11.0jackson-module-parameter-names-2.11.0.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-tomcat2.3.1.RELEASEspring-boot-starter-tomcat-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgapache	omcatembed	omcat-embed-core9.0.36	omcat-embed-core-9.0.36.jar;F:apache-maven-3.6.0
    epositoryorgglassfishjakarta.el3.0.3jakarta.el-3.0.3.jar;F:apache-maven-3.6.0
    epositoryorgapache	omcatembed	omcat-embed-websocket9.0.36	omcat-embed-websocket-9.0.36.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-web5.2.7.RELEASEspring-web-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-beans5.2.7.RELEASEspring-beans-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-webmvc5.2.7.RELEASEspring-webmvc-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-aop5.2.7.RELEASEspring-aop-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-context5.2.7.RELEASEspring-context-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-expression5.2.7.RELEASEspring-expression-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-devtools2.3.1.RELEASEspring-boot-devtools-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot2.3.1.RELEASEspring-boot-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-autoconfigure2.3.1.RELEASEspring-boot-autoconfigure-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-data-jpa2.3.1.RELEASEspring-boot-starter-data-jpa-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-aop2.3.1.RELEASEspring-boot-starter-aop-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgaspectjaspectjweaver1.9.5aspectjweaver-1.9.5.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-jdbc2.3.1.RELEASEspring-boot-starter-jdbc-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositorycomzaxxerHikariCP3.4.5HikariCP-3.4.5.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-jdbc5.2.7.RELEASEspring-jdbc-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryjakarta	ransactionjakarta.transaction-api1.3.3jakarta.transaction-api-1.3.3.jar;F:apache-maven-3.6.0
    epositoryjakartapersistencejakarta.persistence-api2.2.3jakarta.persistence-api-2.2.3.jar;F:apache-maven-3.6.0
    epositoryorghibernatehibernate-core5.4.17.Finalhibernate-core-5.4.17.Final.jar;F:apache-maven-3.6.0
    epositoryorgjbossloggingjboss-logging3.4.1.Finaljboss-logging-3.4.1.Final.jar;F:apache-maven-3.6.0
    epositoryorgjavassistjavassist3.24.0-GAjavassist-3.24.0-GA.jar;F:apache-maven-3.6.0
    epository
    etytebuddyyte-buddy1.10.11yte-buddy-1.10.11.jar;F:apache-maven-3.6.0
    epositoryantlrantlr2.7.7antlr-2.7.7.jar;F:apache-maven-3.6.0
    epositoryorgjbossjandex2.1.3.Finaljandex-2.1.3.Final.jar;F:apache-maven-3.6.0
    epositorycomfasterxmlclassmate1.5.1classmate-1.5.1.jar;F:apache-maven-3.6.0
    epositoryorgdom4jdom4j2.1.3dom4j-2.1.3.jar;F:apache-maven-3.6.0
    epositoryorghibernatecommonhibernate-commons-annotations5.1.0.Finalhibernate-commons-annotations-5.1.0.Final.jar;F:apache-maven-3.6.0
    epositoryorgglassfishjaxbjaxb-runtime2.3.3jaxb-runtime-2.3.3.jar;F:apache-maven-3.6.0
    epositoryorgglassfishjaxb	xw22.3.3	xw2-2.3.3.jar;F:apache-maven-3.6.0
    epositorycomsunistackistack-commons-runtime3.0.11istack-commons-runtime-3.0.11.jar;F:apache-maven-3.6.0
    epositorycomsunactivationjakarta.activation1.2.2jakarta.activation-1.2.2.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkdataspring-data-jpa2.3.1.RELEASEspring-data-jpa-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkdataspring-data-commons2.3.1.RELEASEspring-data-commons-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-orm5.2.7.RELEASEspring-orm-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-tx5.2.7.RELEASEspring-tx-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-aspects5.2.7.RELEASEspring-aspects-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositorymysqlmysql-connector-java8.0.20mysql-connector-java-8.0.20.jar;F:apache-maven-3.6.0
    epositoryorgmybatisspringootmybatis-spring-boot-starter1.1.1mybatis-spring-boot-starter-1.1.1.jar;F:apache-maven-3.6.0
    epositoryorgmybatisspringootmybatis-spring-boot-autoconfigure1.1.1mybatis-spring-boot-autoconfigure-1.1.1.jar;F:apache-maven-3.6.0
    epositoryorgmybatismybatis3.4.0mybatis-3.4.0.jar;F:apache-maven-3.6.0
    epositoryorgmybatismybatis-spring1.3.0mybatis-spring-1.3.0.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-redis1.3.8.RELEASEspring-boot-starter-redis-1.3.8.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkdataspring-data-redis2.3.1.RELEASEspring-data-redis-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkdataspring-data-keyvalue2.3.1.RELEASEspring-data-keyvalue-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-oxm5.2.7.RELEASEspring-oxm-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-context-support5.2.7.RELEASEspring-context-support-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epository
    edisclientsjedis3.3.0jedis-3.3.0.jar;F:apache-maven-3.6.0
    epositoryorgapachecommonscommons-pool22.8.0commons-pool2-2.8.0.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-starter-test2.3.1.RELEASEspring-boot-starter-test-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-test2.3.1.RELEASEspring-boot-test-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkootspring-boot-test-autoconfigure2.3.1.RELEASEspring-boot-test-autoconfigure-2.3.1.RELEASE.jar;F:apache-maven-3.6.0
    epositorycomjaywayjsonpathjson-path2.4.0json-path-2.4.0.jar;F:apache-maven-3.6.0
    epository
    etminidevjson-smart2.3json-smart-2.3.jar;F:apache-maven-3.6.0
    epository
    etminidevaccessors-smart1.2accessors-smart-1.2.jar;F:apache-maven-3.6.0
    epositoryorgow2asmasm5.0.4asm-5.0.4.jar;F:apache-maven-3.6.0
    epositoryjakartaxmlindjakarta.xml.bind-api2.3.3jakarta.xml.bind-api-2.3.3.jar;F:apache-maven-3.6.0
    epositoryjakartaactivationjakarta.activation-api1.2.2jakarta.activation-api-1.2.2.jar;F:apache-maven-3.6.0
    epositoryorgassertjassertj-core3.16.1assertj-core-3.16.1.jar;F:apache-maven-3.6.0
    epositoryorghamcresthamcrest2.2hamcrest-2.2.jar;F:apache-maven-3.6.0
    epositoryorgjunitjupiterjunit-jupiter5.6.2junit-jupiter-5.6.2.jar;F:apache-maven-3.6.0
    epositoryorgjunitjupiterjunit-jupiter-api5.6.2junit-jupiter-api-5.6.2.jar;F:apache-maven-3.6.0
    epositoryorgopentest4jopentest4j1.2.0opentest4j-1.2.0.jar;F:apache-maven-3.6.0
    epositoryorgjunitplatformjunit-platform-commons1.6.2junit-platform-commons-1.6.2.jar;F:apache-maven-3.6.0
    epositoryorgjunitjupiterjunit-jupiter-params5.6.2junit-jupiter-params-5.6.2.jar;F:apache-maven-3.6.0
    epositoryorgjunitjupiterjunit-jupiter-engine5.6.2junit-jupiter-engine-5.6.2.jar;F:apache-maven-3.6.0
    epositoryorgjunitvintagejunit-vintage-engine5.6.2junit-vintage-engine-5.6.2.jar;F:apache-maven-3.6.0
    epositoryorgapiguardianapiguardian-api1.1.0apiguardian-api-1.1.0.jar;F:apache-maven-3.6.0
    epositoryorgjunitplatformjunit-platform-engine1.6.2junit-platform-engine-1.6.2.jar;F:apache-maven-3.6.0
    epositoryjunitjunit4.13junit-4.13.jar;F:apache-maven-3.6.0
    epositoryorgmockitomockito-core3.3.3mockito-core-3.3.3.jar;F:apache-maven-3.6.0
    epository
    etytebuddyyte-buddy-agent1.10.11yte-buddy-agent-1.10.11.jar;F:apache-maven-3.6.0
    epositoryorgobjenesisobjenesis2.6objenesis-2.6.jar;F:apache-maven-3.6.0
    epositoryorgmockitomockito-junit-jupiter3.3.3mockito-junit-jupiter-3.3.3.jar;F:apache-maven-3.6.0
    epositoryorgskyscreamerjsonassert1.5.0jsonassert-1.5.0.jar;F:apache-maven-3.6.0
    epositorycomvaadinexternalgoogleandroid-json.0.20131108.vaadin1android-json-0.0.20131108.vaadin1.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-core5.2.7.RELEASEspring-core-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-jcl5.2.7.RELEASEspring-jcl-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgspringframeworkspring-test5.2.7.RELEASEspring-test-5.2.7.RELEASE.jar;F:apache-maven-3.6.0
    epositoryorgxmlunitxmlunit-core2.7.0xmlunit-core-2.7.0.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.example.test.Test,readConfigFile
    23:50:07.958 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.example.test.Test]
    23:50:07.972 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
    23:50:07.990 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
    23:50:08.116 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.test.Test] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
    23:50:08.166 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.test.Test], using SpringBootContextLoader
    23:50:08.180 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.test.Test]: class path resource [com/example/test/Test-context.xml] does not exist
    23:50:08.183 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.test.Test]: class path resource [com/example/test/TestContext.groovy] does not exist
    23:50:08.183 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.test.Test]: no resource found for suffixes {-context.xml, Context.groovy}.
    23:50:08.286 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.test.Test]
    23:50:08.587 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.test.Test]: using defaults.
    23:50:08.588 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
    23:50:08.644 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@1ebea008, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@72d6b3ba, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@1787f2a0, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@7de62196, org.springframework.test.context.support.DirtiesContextTestExecutionListener@163370c2, org.springframework.test.context.transaction.TransactionalTestExecutionListener@51bf5add, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@7905a0b8, org.springframework.test.context.event.EventPublishingTestExecutionListener@35a3d49f, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@389b0789, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@13d9cbf5, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@478db956, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@6ca18a14, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@c667f46, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@51bd8b5c]
    23:50:08.650 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.655 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]
    23:50:08.658 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.659 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]
    23:50:08.659 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.659 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]23:50:08.694 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.694 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]23:50:08.697 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.697 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]
    23:50:08.701 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.702 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]
    23:50:08.719 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@6692b6c6 testClass = Test, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@1cd629b3 testClass = Test, locations = '{}', classes = '{class com.CleanSpringBootApplication, class com.CleanSpringBootApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@4988d8b8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@6913c1fb, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7ee8290b, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@15ca7889, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
    23:50:08.723 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.test.Test]
    23:50:08.725 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.test.Test]
    23:50:08.818 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
    
      .   ____          _            __ _ _
     /\ / ___'_ __ _ _(_)_ __  __ _    
    ( ( )\___ | '_ | '_| | '_ / _` |    
     \/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.3.1.RELEASE)
    
    2020-07-18 23:50:10.901  INFO 16360 --- [           main] com.example.test.Test                    : Starting Test on DESKTOP-2PVNKVI with PID 16360 (started by Administrator in D:学习代码javacleanSpringBoot)
    2020-07-18 23:50:10.908  INFO 16360 --- [           main] com.example.test.Test                    : No active profile set, falling back to default profiles: default
    2020-07-18 23:50:18.360  INFO 16360 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
    2020-07-18 23:50:18.363  INFO 16360 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
    2020-07-18 23:50:19.856  INFO 16360 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1471ms. Found 1 JPA repository interfaces.
    2020-07-18 23:50:19.889  INFO 16360 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
    2020-07-18 23:50:19.890  INFO 16360 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
    2020-07-18 23:50:20.968  INFO 16360 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.example.dao.IUserDao. If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository.
    2020-07-18 23:50:20.969  INFO 16360 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1060ms. Found 0 Redis repository interfaces.
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    2020-07-18 23:50:23.201  INFO 16360 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-07-18 23:50:24.088  INFO 16360 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
    2020-07-18 23:50:24.479  INFO 16360 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.17.Final
    2020-07-18 23:50:25.672  INFO 16360 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
    2020-07-18 23:50:26.227  WARN 16360 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
    2020-07-18 23:50:27.203  INFO 16360 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
    2020-07-18 23:50:27.218  WARN 16360 --- [         task-1] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
    2020-07-18 23:50:28.376  INFO 16360 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
    2020-07-18 23:50:28.424  INFO 16360 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
    2020-07-18 23:50:28.473  INFO 16360 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
    2020-07-18 23:50:30.315  INFO 16360 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
    2020-07-18 23:50:30.334  INFO 16360 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
    2020-07-18 23:50:30.720  INFO 16360 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
    2020-07-18 23:50:30.736  INFO 16360 --- [           main] com.example.test.Test                    : Started Test in 21.891 seconds (JVM running for 24.626)
    com.mysql.jdbc.Driver
    2020-07-18 23:50:31.000  INFO 16360 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
    2020-07-18 23:50:31.003  INFO 16360 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
    2020-07-18 23:50:31.005  INFO 16360 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
    2020-07-18 23:50:31.041  INFO 16360 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
    
    Process finished with exit code 0

    方法2:绑定对象bean调用

    1、在application.properties或者application.yml里面添加我们的配置项:

     2、创建一个配置类(该类和我们上面配置项的属性一一对应):

    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    
    @Component
    @ConfigurationProperties(prefix = "upload")
    public class PropertiesConfig {
        private  int port;
    
        public int getPort() {
            return port;
        }
    
        public void setPort(int port) {
            this.port = port;
        }
    }

    3、在需要调用的地方自动装配上我们上面的类并按照下面的方式获得配置项的值:

    @Controller
    @RequestMapping("/update/send")
    public class UpdateSendController extends BaseController {    
    @Autowired
        private PropertiesConfig propertiesconfig;
        int port = propertiesconfig.getPort();
    }
  • 相关阅读:
    Vulnhub系列:Tomato(文件包含getshell)
    Linux基础之终端、控制台、tty、pty简介说明
    linux服务器之间传输文件的四种方式
    Vulnhub系列:Os-hackNos
    [GXYCTF2019]BabyUpload
    CVE-2018-12613
    [MRCTF2020]Ez_bypass
    [BUUCTF 2018]Online Tool
    [BJDCTF 2nd]fake google
    [网鼎杯 2020 青龙组]AreUSerialz
  • 原文地址:https://www.cnblogs.com/luzhanshi/p/12093903.html
Copyright © 2011-2022 走看看