[转] Spring - Java Based Configuration

本文详细介绍了Spring Boot中使用Java进行配置的方法,包括@Configuration、@Bean等注解的应用,依赖注入方式,@Import注解的使用,以及初始化和销毁回调方法的指定等内容。

PS: Spring boot注解,Configuration是生成一个config对象,@Bean指定对应的函数返回的是Bean对象,相当于XML定义,ConfigurationProperties是指定对应的函数返回的保护这些properties

http://www.tutorialspoint.com/spring/spring_java_based_configuration.htm

So far you have seen how we configure Spring beans using XML configuration file. If you are comfortable with XML configuration, then I will say it is really not required to learn how to proceed with Java based configuration because you are going to achieve the same result using either of the configurations available.

Java based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations explained below.

@Configuration & @Bean Annotations:

Annotating a class with the @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context. The simplest possible @Configuration class would be as follows:

package com.tutorialspoint;
import org.springframework.context.annotation.*;

@Configuration
public class HelloWorldConfig {

   @Bean 
   public HelloWorld helloWorld(){
      return new HelloWorld();
   }
}

Above code will be equivalent to the following XML configuration:

<beans>
   <bean id="helloWorld" class="com.tutorialspoint.HelloWorld" />
</beans>

Here the method name annotated with @Bean works as bean ID and it creates and returns actual bean. Your configuration class can have declaration for more than one @Bean. Once your configuration classes are defined, you can load & provide them to Spring container using AnnotationConfigApplicationContext as follows:

public static void main(String[] args) {
   ApplicationContext ctx = 
   new AnnotationConfigApplicationContext(HelloWorldConfig.class);
   
   HelloWorld helloWorld = ctx.getBean(HelloWorld.class);

   helloWorld.setMessage("Hello World!");
   helloWorld.getMessage();
}

You can load various configuration classes as follows:

public static void main(String[] args) {
   AnnotationConfigApplicationContext ctx = 
   new AnnotationConfigApplicationContext();

   ctx.register(AppConfig.class, OtherConfig.class);
   ctx.register(AdditionalConfig.class);
   ctx.refresh();

   MyService myService = ctx.getBean(MyService.class);
   myService.doStuff();
}

Example:

Let us have working Eclipse IDE in place and follow the following steps to create a Spring application:

StepDescription
1Create a project with a name SpringExample and create a package com.tutorialspoint under the src folder in the created project.
2Add required Spring libraries using Add External JARs option as explained in the Spring Hello World Example chapter.
3Because you are using Java-based annotations, so you also need to add CGLIB.jar from your Java installation directory and ASM.jar library which can be downloaded from asm.ow2.org.
4Create Java classes HelloWorldConfig, HelloWorld and MainApp under the com.tutorialspoint package.
5The final step is to create the content of all the Java files and Bean Configuration file and run the application as explained below.

Here is the content of HelloWorldConfig.java file:

package com.tutorialspoint;
import org.springframework.context.annotation.*;

@Configuration
public class HelloWorldConfig {

   @Bean 
   public HelloWorld helloWorld(){
      return new HelloWorld();
   }
}

Here is the content of HelloWorld.java file:

package com.tutorialspoint;

public class HelloWorld {
   private String message;

   public void setMessage(String message){
      this.message  = message;
   }

   public void getMessage(){
      System.out.println("Your Message : " + message);
   }
}

Following is the content of the MainApp.java file:

package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext ctx = 
      new AnnotationConfigApplicationContext(HelloWorldConfig.class);
   
      HelloWorld helloWorld = ctx.getBean(HelloWorld.class);

      helloWorld.setMessage("Hello World!");
      helloWorld.getMessage();
   }
}

Once you are done with creating all the source filesand adding required additional libraries, let us run the application. You should note that there is no configuration file required. If everything is fine with your application, this will print the following message:

Your Message : Hello World!

Injecting Bean Dependencies:

When @Beans have dependencies on one another, expressing that dependency is as simple as having one bean method calling another as follows:

package com.tutorialspoint;
import org.springframework.context.annotation.*;

@Configuration
public class AppConfig {
   @Bean
   public Foo foo() {
      return new Foo(bar());
   }
   @Bean
   public Bar bar() {
      return new Bar();
   }
}

Here, the foo bean receives a reference to bar via constructor injection. Now let us see one working example:

Example:

Let us have working Eclipse IDE in place and follow the following steps to create a Spring application:

StepDescription
1Create a project with a name SpringExample and create a package com.tutorialspoint under the src folder in the created project.
2Add required Spring libraries using Add External JARs option as explained in the Spring Hello World Example chapter.
3Because you are using Java-based annotations, so you also need to add CGLIB.jar from your Java installation directory and ASM.jar library which can be downloaded from asm.ow2.org.
4Create Java classes TextEditorConfig, TextEditor, SpellChecker and MainApp under the com.tutorialspoint package.
5The final step is to create the content of all the Java files and Bean Configuration file and run the application as explained below.

Here is the content of TextEditorConfig.java file:

package com.tutorialspoint;
import org.springframework.context.annotation.*;

@Configuration
public class TextEditorConfig {

   @Bean 
   public TextEditor textEditor(){
      return new TextEditor( spellChecker() );
   }

   @Bean 
   public SpellChecker spellChecker(){
      return new SpellChecker( );
   }
}

Here is the content of TextEditor.java file:

package com.tutorialspoint;

public class TextEditor {
   private SpellChecker spellChecker;

   public TextEditor(SpellChecker spellChecker){
      System.out.println("Inside TextEditor constructor." );
      this.spellChecker = spellChecker;
   }
   public void spellCheck(){
      spellChecker.checkSpelling();
   }
}

Following is the content of another dependent class file SpellChecker.java:

package com.tutorialspoint;

public class SpellChecker {
   public SpellChecker(){
      System.out.println("Inside SpellChecker constructor." );
   }

   public void checkSpelling(){
      System.out.println("Inside checkSpelling." );
   }
   
}

Following is the content of the MainApp.java file:

package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext ctx = 
      new AnnotationConfigApplicationContext(TextEditorConfig.class);

      TextEditor te = ctx.getBean(TextEditor.class);

      te.spellCheck();
   }
}

Once you are done with creating all the source filesand adding required additional libraries, let us run the application. You should note that there is no configuration file required. If everything is fine with your application, this will print the following message:

Inside SpellChecker constructor.
Inside TextEditor constructor.
Inside checkSpelling.

The @Import Annotation:

The @Import annotation allows for loading @Bean definitions from another configuration class. Consider a ConfigA class as follows:

@Configuration
public class ConfigA {
   @Bean
   public A a() {
      return new A(); 
   }
}

You can import above Bean declaration in another Bean Declaration as follows:

@Configuration
@Import(ConfigA.class)
public class ConfigB {
   @Bean
   public B a() {
      return new A(); 
   }
}

Now, rather than needing to specify both ConfigA.class and ConfigB.class when instantiating the context, only ConfigB needs to be supplied as follows:

public static void main(String[] args) {
   ApplicationContext ctx = 
   new AnnotationConfigApplicationContext(ConfigB.class);
   // now both beans A and B will be available...
   A a = ctx.getBean(A.class);
   B b = ctx.getBean(B.class);
}

Lifecycle Callbacks:

The @Bean annotation supports specifying arbitrary initialization and destruction callback methods, much like Spring XML's init-method and destroy-method attributes on the bean element:

public class Foo {
   public void init() {
      // initialization logic
   }
   public void cleanup() {
      // destruction logic
   }
}

@Configuration
public class AppConfig {
   @Bean(initMethod = "init", destroyMethod = "cleanup" )
   public Foo foo() {
      return new Foo();
   }
}

Specifying Bean Scope:

The default scope is singleton, but you can override this with the @Scope annotation as follows:

@Configuration
public class AppConfig {
   @Bean
   @Scope("prototype")
   public Foo foo() {
      return new Foo();
   }
}

转载于:https://www.cnblogs.com/qiangxia/p/5688672.html

C:\Users\Lenovo\.jdks\corretto-1.8.0_462\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:D:\IntelliJ IDEA 2025.2\lib\idea_rt.jar=2427" -Dfile.encoding=UTF-8 -classpath "C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\charsets.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\access-bridge-64.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\cldrdata.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\dnsns.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\jaccess.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\jfxrt.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\localedata.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\nashorn.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\sunec.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\sunjce_provider.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\sunmscapi.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\sunpkcs11.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\ext\zipfs.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\jce.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\jfr.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\jfxswt.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\jsse.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\management-agent.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\resources.jar;C:\Users\Lenovo\.jdks\corretto-1.8.0_462\jre\lib\rt.jar;E:\前后端代码\shigong-new_20250810 (2)\shigong-new - 副本\ruoyi-modules\activiti\target\classes;C:\JAVA\repository\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-discovery\2021.0.5.0\spring-cloud-starter-alibaba-nacos-discovery-2021.0.5.0.jar;C:\JAVA\repository\com\alibaba\cloud\spring-cloud-alibaba-commons\2021.0.5.0\spring-cloud-alibaba-commons-2021.0.5.0.jar;C:\JAVA\repository\com\alibaba\nacos\nacos-client\2.2.0\nacos-client-2.2.0.jar;C:\JAVA\repository\com\alibaba\nacos\nacos-auth-plugin\2.2.0\nacos-auth-plugin-2.2.0.jar;C:\JAVA\repository\com\alibaba\nacos\nacos-encryption-plugin\2.2.0\nacos-encryption-plugin-2.2.0.jar;C:\JAVA\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\JAVA\repository\org\apache\httpcomponents\httpasyncclient\4.1.5\httpasyncclient-4.1.5.jar;C:\JAVA\repository\org\apache\httpcomponents\httpcore-nio\4.4.16\httpcore-nio-4.4.16.jar;C:\JAVA\repository\io\prometheus\simpleclient\0.15.0\simpleclient-0.15.0.jar;C:\JAVA\repository\io\prometheus\simpleclient_tracer_otel\0.15.0\simpleclient_tracer_otel-0.15.0.jar;C:\JAVA\repository\io\prometheus\simpleclient_tracer_common\0.15.0\simpleclient_tracer_common-0.15.0.jar;C:\JAVA\repository\io\prometheus\simpleclient_tracer_otel_agent\0.15.0\simpleclient_tracer_otel_agent-0.15.0.jar;C:\JAVA\repository\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;C:\JAVA\repository\com\alibaba\spring\spring-context-support\1.0.11\spring-context-support-1.0.11.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-commons\3.1.7\spring-cloud-commons-3.1.7.jar;C:\JAVA\repository\org\springframework\security\spring-security-crypto\5.7.9\spring-security-crypto-5.7.9.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-context\3.1.7\spring-cloud-context-3.1.7.jar;C:\JAVA\repository\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-config\2021.0.5.0\spring-cloud-starter-alibaba-nacos-config-2021.0.5.0.jar;C:\JAVA\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\JAVA\repository\com\mysql\mysql-connector-j\8.0.33\mysql-connector-j-8.0.33.jar;E:\前后端代码\shigong-new_20250810 (2)\shigong-new - 副本\ruoyi-common\ruoyi-common-core\target\classes;C:\JAVA\repository\org\springframework\cloud\spring-cloud-starter-openfeign\3.1.8\spring-cloud-starter-openfeign-3.1.8.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-openfeign-core\3.1.8\spring-cloud-openfeign-core-3.1.8.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-aop\2.7.13\spring-boot-starter-aop-2.7.13.jar;C:\JAVA\repository\org\aspectj\aspectjweaver\1.9.7\aspectjweaver-1.9.7.jar;C:\JAVA\repository\io\github\openfeign\form\feign-form-spring\3.8.0\feign-form-spring-3.8.0.jar;C:\JAVA\repository\io\github\openfeign\form\feign-form\3.8.0\feign-form-3.8.0.jar;C:\JAVA\repository\commons-fileupload\commons-fileupload\1.5\commons-fileupload-1.5.jar;C:\JAVA\repository\io\github\openfeign\feign-core\11.10\feign-core-11.10.jar;C:\JAVA\repository\io\github\openfeign\feign-slf4j\11.10\feign-slf4j-11.10.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-starter-loadbalancer\3.1.7\spring-cloud-starter-loadbalancer-3.1.7.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-loadbalancer\3.1.7\spring-cloud-loadbalancer-3.1.7.jar;C:\JAVA\repository\io\projectreactor\reactor-core\3.4.30\reactor-core-3.4.30.jar;C:\JAVA\repository\org\reactivestreams\reactive-streams\1.0.4\reactive-streams-1.0.4.jar;C:\JAVA\repository\io\projectreactor\addons\reactor-extra\3.4.10\reactor-extra-3.4.10.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-cache\2.7.13\spring-boot-starter-cache-2.7.13.jar;C:\JAVA\repository\com\stoyanr\evictor\1.0.0\evictor-1.0.0.jar;C:\JAVA\repository\org\springframework\spring-context-support\5.3.28\spring-context-support-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-beans\5.3.28\spring-beans-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-context\5.3.28\spring-context-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-aop\5.3.28\spring-aop-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-expression\5.3.28\spring-expression-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-core\5.3.28\spring-core-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-jcl\5.3.28\spring-jcl-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-web\5.3.28\spring-web-5.3.28.jar;C:\JAVA\repository\com\alibaba\transmittable-thread-local\2.14.3\transmittable-thread-local-2.14.3.jar;C:\JAVA\repository\com\github\pagehelper\pagehelper-spring-boot-starter\1.4.7\pagehelper-spring-boot-starter-1.4.7.jar;C:\JAVA\repository\com\github\pagehelper\pagehelper-spring-boot-autoconfigure\1.4.7\pagehelper-spring-boot-autoconfigure-1.4.7.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-validation\2.7.13\spring-boot-starter-validation-2.7.13.jar;C:\JAVA\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.76\tomcat-embed-el-9.0.76.jar;C:\JAVA\repository\org\hibernate\validator\hibernate-validator\6.2.5.Final\hibernate-validator-6.2.5.Final.jar;C:\JAVA\repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;C:\JAVA\repository\org\jboss\logging\jboss-logging\3.4.3.Final\jboss-logging-3.4.3.Final.jar;C:\JAVA\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;C:\JAVA\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\JAVA\repository\com\alibaba\fastjson2\fastjson2\2.0.39\fastjson2-2.0.39.jar;C:\JAVA\repository\io\jsonwebtoken\jjwt\0.9.1\jjwt-0.9.1.jar;C:\JAVA\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\JAVA\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\JAVA\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\JAVA\repository\commons-io\commons-io\2.13.0\commons-io-2.13.0.jar;C:\JAVA\repository\org\apache\poi\poi-ooxml\4.1.2\poi-ooxml-4.1.2.jar;C:\JAVA\repository\org\apache\poi\poi-ooxml-schemas\4.1.2\poi-ooxml-schemas-4.1.2.jar;C:\JAVA\repository\org\apache\xmlbeans\xmlbeans\3.1.0\xmlbeans-3.1.0.jar;C:\JAVA\repository\com\github\virtuald\curvesapi\1.06\curvesapi-1.06.jar;C:\JAVA\repository\org\apache\poi\poi\4.1.2\poi-4.1.2.jar;C:\JAVA\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;C:\JAVA\repository\org\apache\commons\commons-math3\3.6.1\commons-math3-3.6.1.jar;C:\JAVA\repository\com\zaxxer\SparseBitSet\1.2\SparseBitSet-1.2.jar;C:\JAVA\repository\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar;C:\JAVA\repository\com\baomidou\mybatis-plus-boot-starter\3.3.0\mybatis-plus-boot-starter-3.3.0.jar;C:\JAVA\repository\com\baomidou\mybatis-plus\3.3.0\mybatis-plus-3.3.0.jar;C:\JAVA\repository\com\baomidou\mybatis-plus-extension\3.3.0\mybatis-plus-extension-3.3.0.jar;C:\JAVA\repository\com\baomidou\mybatis-plus-core\3.3.0\mybatis-plus-core-3.3.0.jar;C:\JAVA\repository\com\baomidou\mybatis-plus-annotation\3.3.0\mybatis-plus-annotation-3.3.0.jar;C:\JAVA\repository\org\apache\httpcomponents\httpclient\4.5.14\httpclient-4.5.14.jar;C:\JAVA\repository\org\apache\httpcomponents\httpmime\4.5.14\httpmime-4.5.14.jar;C:\JAVA\repository\cn\hutool\hutool-all\5.3.4\hutool-all-5.3.4.jar;C:\JAVA\repository\org\apache\httpcomponents\httpcore\4.4.16\httpcore-4.4.16.jar;C:\JAVA\repository\com\drewnoakes\metadata-extractor\2.15.0\metadata-extractor-2.15.0.jar;C:\JAVA\repository\com\adobe\xmp\xmpcore\6.0.6\xmpcore-6.0.6.jar;C:\JAVA\repository\com\belerweb\pinyin4j\2.5.0\pinyin4j-2.5.0.jar;C:\JAVA\repository\commons-beanutils\commons-beanutils\1.9.4\commons-beanutils-1.9.4.jar;C:\JAVA\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\JAVA\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;C:\JAVA\repository\org\locationtech\proj4j\proj4j\1.3.0\proj4j-1.3.0.jar;C:\JAVA\repository\org\locationtech\proj4j\proj4j-epsg\1.3.0\proj4j-epsg-1.3.0.jar;C:\JAVA\repository\org\jsoup\jsoup\1.12.1\jsoup-1.12.1.jar;C:\JAVA\repository\org\freemarker\freemarker\2.3.32\freemarker-2.3.32.jar;E:\前后端代码\shigong-new_20250810 (2)\shigong-new - 副本\ruoyi-common\ruoyi-common-log\target\classes;E:\前后端代码\shigong-new_20250810 (2)\shigong-new - 副本\ruoyi-common\ruoyi-common-security\target\classes;C:\JAVA\repository\org\springframework\spring-webmvc\5.3.28\spring-webmvc-5.3.28.jar;E:\前后端代码\shigong-new_20250810 (2)\shigong-new - 副本\ruoyi-api\ruoyi-api-system\target\classes;E:\前后端代码\shigong-new_20250810 (2)\shigong-new - 副本\ruoyi-common\ruoyi-common-redis\target\classes;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-data-redis\2.7.13\spring-boot-starter-data-redis-2.7.13.jar;C:\JAVA\repository\org\springframework\data\spring-data-redis\2.7.13\spring-data-redis-2.7.13.jar;C:\JAVA\repository\org\springframework\data\spring-data-keyvalue\2.7.13\spring-data-keyvalue-2.7.13.jar;C:\JAVA\repository\org\springframework\data\spring-data-commons\2.7.13\spring-data-commons-2.7.13.jar;C:\JAVA\repository\org\springframework\spring-oxm\5.3.28\spring-oxm-5.3.28.jar;C:\JAVA\repository\redis\clients\jedis\3.8.0\jedis-3.8.0.jar;C:\JAVA\repository\org\apache\commons\commons-pool2\2.11.1\commons-pool2-2.11.1.jar;C:\JAVA\repository\org\gavaghan\geodesy\1.1.3\geodesy-1.1.3.jar;C:\JAVA\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.1.3\mybatis-spring-boot-starter-2.1.3.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter\2.7.13\spring-boot-starter-2.7.13.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-logging\2.7.13\spring-boot-starter-logging-2.7.13.jar;C:\JAVA\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\JAVA\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\JAVA\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;C:\JAVA\repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;C:\JAVA\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-jdbc\2.7.13\spring-boot-starter-jdbc-2.7.13.jar;C:\JAVA\repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;C:\JAVA\repository\org\springframework\spring-jdbc\5.3.28\spring-jdbc-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-tx\5.3.28\spring-tx-5.3.28.jar;C:\JAVA\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.1.3\mybatis-spring-boot-autoconfigure-2.1.3.jar;C:\JAVA\repository\org\mybatis\mybatis\3.5.5\mybatis-3.5.5.jar;C:\JAVA\repository\org\mybatis\mybatis-spring\2.0.5\mybatis-spring-2.0.5.jar;C:\JAVA\repository\org\apache\logging\log4j\log4j-api\2.17.1\log4j-api-2.17.1.jar;C:\JAVA\repository\com\github\pagehelper\pagehelper\5.1.8\pagehelper-5.1.8.jar;C:\JAVA\repository\com\github\jsqlparser\jsqlparser\1.2\jsqlparser-1.2.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-websocket\2.7.13\spring-boot-starter-websocket-2.7.13.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-web\2.7.13\spring-boot-starter-web-2.7.13.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-json\2.7.13\spring-boot-starter-json-2.7.13.jar;C:\JAVA\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\JAVA\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\JAVA\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-starter-tomcat\2.7.13\spring-boot-starter-tomcat-2.7.13.jar;C:\JAVA\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.76\tomcat-embed-core-9.0.76.jar;C:\JAVA\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.76\tomcat-embed-websocket-9.0.76.jar;C:\JAVA\repository\org\springframework\spring-messaging\5.3.28\spring-messaging-5.3.28.jar;C:\JAVA\repository\org\springframework\spring-websocket\5.3.28\spring-websocket-5.3.28.jar;C:\JAVA\repository\org\projectlombok\lombok\1.18.28\lombok-1.18.28.jar;C:\JAVA\repository\io\minio\minio\8.4.5\minio-8.4.5.jar;C:\JAVA\repository\com\carrotsearch\thirdparty\simple-xml-safe\2.7.1\simple-xml-safe-2.7.1.jar;C:\JAVA\repository\com\google\guava\guava\30.1.1-jre\guava-30.1.1-jre.jar;C:\JAVA\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\JAVA\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\JAVA\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\JAVA\repository\org\checkerframework\checker-qual\3.8.0\checker-qual-3.8.0.jar;C:\JAVA\repository\com\google\errorprone\error_prone_annotations\2.5.1\error_prone_annotations-2.5.1.jar;C:\JAVA\repository\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;C:\JAVA\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.5\jackson-annotations-2.13.5.jar;C:\JAVA\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\JAVA\repository\org\bouncycastle\bcprov-jdk15on\1.69\bcprov-jdk15on-1.69.jar;C:\JAVA\repository\org\apache\commons\commons-compress\1.21\commons-compress-1.21.jar;C:\JAVA\repository\org\xerial\snappy\snappy-java\1.1.8.4\snappy-java-1.1.8.4.jar;C:\JAVA\repository\com\squareup\okhttp3\okhttp\4.9.0\okhttp-4.9.0.jar;C:\JAVA\repository\com\squareup\okio\okio\2.8.0\okio-2.8.0.jar;C:\JAVA\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.6.21\kotlin-stdlib-common-1.6.21.jar;C:\JAVA\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.21\kotlin-stdlib-1.6.21.jar;C:\JAVA\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\JAVA\repository\net\coobird\thumbnailator\0.4.8\thumbnailator-0.4.8.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-starter-bootstrap\3.1.7\spring-cloud-starter-bootstrap-3.1.7.jar;C:\JAVA\repository\org\springframework\cloud\spring-cloud-starter\3.1.7\spring-cloud-starter-3.1.7.jar;C:\JAVA\repository\org\springframework\security\spring-security-rsa\1.0.11.RELEASE\spring-security-rsa-1.0.11.RELEASE.jar;C:\JAVA\repository\org\bouncycastle\bcpkix-jdk15on\1.69\bcpkix-jdk15on-1.69.jar;C:\JAVA\repository\org\bouncycastle\bcutil-jdk15on\1.69\bcutil-jdk15on-1.69.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-configuration-processor\2.7.13\spring-boot-configuration-processor-2.7.13.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-devtools\2.7.13\spring-boot-devtools-2.7.13.jar;C:\JAVA\repository\org\springframework\boot\spring-boot\2.7.13\spring-boot-2.7.13.jar;C:\JAVA\repository\org\springframework\boot\spring-boot-autoconfigure\2.7.13\spring-boot-autoconfigure-2.7.13.jar" com.yupont.app.ActivitiApplication 10:13:52.793 [Thread-1] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@28b66390 2025-08-21 10:13:53.059 INFO 3976 --- [ restartedMain] c.a.n.client.env.SearchableProperties : properties search order:PROPERTIES->JVM->ENV->DEFAULT_SETTING 2025-08-21 10:13:53.175 INFO 3976 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2025-08-21 10:13:53.382 INFO 3976 --- [ restartedMain] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success. 2025-08-21 10:13:53.382 INFO 3976 --- [ restartedMain] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success. . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.13) 2025-08-21 10:14:00.385 WARN 3976 --- [ restartedMain] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[null.properties] & group[DEFAULT_GROUP] 2025-08-21 10:14:00.386 INFO 3976 --- [ restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-null.properties,DEFAULT_GROUP'}] 2025-08-21 10:14:00.399 INFO 3976 --- [ restartedMain] com.yupont.app.ActivitiApplication : No active profile set, falling back to 1 default profile: "default" 2025-08-21 10:14:01.046 INFO 3976 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode 2025-08-21 10:14:01.048 INFO 3976 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode. 2025-08-21 10:14:01.059 INFO 3976 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 3 ms. Found 0 Redis repository interfaces. 2025-08-21 10:14:01.160 WARN 3976 --- [ restartedMain] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.yupont.app.*.dao]' package. Please check your configuration. 2025-08-21 10:14:01.199 INFO 3976 --- [ restartedMain] o.s.cloud.context.scope.GenericScope : BeanFactory id=84bfe0a8-a36d-3907-9c5a-a783377777d2 2025-08-21 10:14:01.711 INFO 3976 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2025-08-21 10:14:01.719 INFO 3976 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-08-21 10:14:01.719 INFO 3976 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.76] 2025-08-21 10:14:01.867 INFO 3976 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2025-08-21 10:14:01.867 INFO 3976 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1444 ms 2025-08-21 10:14:02.381 WARN 3976 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class 2025-08-21 10:14:02.382 INFO 3976 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2025-08-21 10:14:02.392 INFO 3976 --- [ restartedMain] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-08-21 10:14:02.410 ERROR 3976 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). 2025-08-21 10:14:02.412 WARN 3976 --- [ Thread-12] c.a.nacos.common.notify.NotifyCenter : [NotifyCenter] Start destroying Publisher 2025-08-21 10:14:02.412 WARN 3976 --- [ Thread-5] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Start destroying common HttpClient 2025-08-21 10:14:02.412 WARN 3976 --- [ Thread-12] c.a.nacos.common.notify.NotifyCenter : [NotifyCenter] Destruction of the end 进程已结束,退出代码为 0
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值