我想測驗 CommandLineRunner 但我不能讓它作業。我只有 2 節課:
框架測驗應用程式.java
包 com.caido.frameworktest;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class FrameworktestApplication { public static void main(String[] args) { System.out.println("Start run"); SpringApplication.run(FrameworktestApplication.class, args); } }
命令列運行程式測驗:
包 com.caido.frameworktest;
import org.springframework.boot.CommandLineRunner; public class CommandLineRunnerTest implements CommandLineRunner { @Override public void run(String... strings) throws Exception { System.err.println("Start CommandLineRunner"); } }
當我運行該應用程式時,我在螢屏上看不到“啟動 CommandLineRunner”。這是完整的輸出:
--- exec-maven-plugin:3.0.0:exec (default-cli) @ frameworktest ---
Start run
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.5)
2022-10-30 20:53:59.862 INFO 14332 --- [ main] c.c.f.FrameworktestApplication : Starting FrameworktestApplication using Java 19.0.1 on DESKTOP-J30M0PF with PID 14332 (Y:\Caido\Dev\test\frameworktest\target\classes started by victor in Y:\Caido\Dev\test\frameworktest)
2022-10-30 20:53:59.866 INFO 14332 --- [ main] c.c.f.FrameworktestApplication : No active profile set, falling back to 1 default profile: "default"
2022-10-30 20:54:01.134 INFO 14332 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-10-30 20:54:01.148 INFO 14332 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-10-30 20:54:01.149 INFO 14332 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-10-30 20:54:01.256 INFO 14332 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-10-30 20:54:01.256 INFO 14332 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1327 ms
2022-10-30 20:54:01.720 INFO 14332 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-10-30 20:54:01.729 INFO 14332 --- [ main] c.c.f.FrameworktestApplication : Started FrameworktestApplication in 2.503 seconds (JVM running for 2.906)
uj5u.com熱心網友回復:
您應該通過注解 @Component 將您的 CommandLineRunnerTest 類標記為 Spring Bean。
在所有 Spring Application Context 啟動并運行后,CommandLineRunner 介面只是添加到 Spring Bean 的“運行”特性(方法“運行”的執行)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/524821.html
標籤:弹簧靴
上一篇:java.sql.SQLException:Parameterindexoutofrange(2>numberofparameters,whichis1)錯誤