gpt4 book ai didi

eclipse - Spring Boot、Spring Loaded、Eclipse、Maven 基本示例

转载 作者:行者123 更新时间:2023-12-02 15:54:28 24 4
gpt4 key购买 nike

我发现 Spring Boot 和 Spring Loaded 的基本示例设置无法根据文档进行工作。我按照 http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application 上的说明进行操作创建一个基本的应用程序,唯一的区别是我将我的类放入一个包中并使用父 pom 的发布版本。应用程序运行良好。然后我将 spring 加载到 pom 文件中,如 doco 中所述。

我使用 mvn spring-boot:run 运行应用程序。

更改我的 Controller 输出,例如“Hello World”到“Hello me”不支持热重载。

我尝试使用其他地方描述的 javaagent 命令行参数作为 java 应用程序运行,但这也不起作用。

pom 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
</parent>

<!-- Additional lines to be added here... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

编译的类可以在这里找到:project_dir\target\classes(我使用的是 Eclipse 和 m2e 插件)。

启动日志:

[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.2.0.RELEASE:run (default-cli) @ myproject >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myproject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\dev\src\scrapi\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\dev\src\scrapi\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ myproject ---
[INFO] No sources to compile
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.2.0.RELEASE:run (default-cli) @ myproject <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.2.0.RELEASE:run (default-cli) @ myproject ---

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.0.RELEASE)

2015-01-02 13:23:25.311 INFO 2180 --- [.Example.main()] first.Example : Starting Example on DEFRAVD804016 with PID 2180 (C:\dev\src\scrapi\target\classes started by john in C:\dev\src\scrapi)
2015-01-02 13:23:25.359 INFO 2180 --- [.Example.main()] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@44354005: startup date [Fri Jan 02 13:23:25 CET 2015]; root of context hierarchy
2015-01-02 13:23:26.193 INFO 2180 --- [.Example.main()] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2015-01-02 13:23:27.121 INFO 2180 --- [.Example.main()] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8182/http
2015-01-02 13:23:27.689 INFO 2180 --- [.Example.main()] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-01-02 13:23:27.691 INFO 2180 --- [.Example.main()] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.15
2015-01-02 13:23:27.814 INFO 2180 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-01-02 13:23:27.814 INFO 2180 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2457 ms
2015-01-02 13:23:28.653 INFO 2180 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-01-02 13:23:28.657 INFO 2180 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-01-02 13:23:28.657 INFO 2180 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-01-02 13:23:28.883 INFO 2180 --- [.Example.main()] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@44354005: startup date [Fri Jan 02 13:23:25 CET 2015]; root of context hierarchy
2015-01-02 13:23:28.995 INFO 2180 --- [.Example.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto java.lang.String first.Example.home()
2015-01-02 13:23:28.997 INFO 2180 --- [.Example.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-01-02 13:23:28.998 INFO 2180 --- [.Example.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2015-01-02 13:23:29.112 INFO 2180 --- [.Example.main()] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-01-02 13:23:29.112 INFO 2180 --- [.Example.main()] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-01-02 13:23:29.160 INFO 2180 --- [.Example.main()] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-01-02 13:23:29.268 INFO 2180 --- [.Example.main()] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2015-01-02 13:23:29.394 INFO 2180 --- [.Example.main()] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8182/http
2015-01-02 13:23:29.399 INFO 2180 --- [.Example.main()] first.Example : Started Example in 4.417 seconds (JVM running for 11.803)

在这种情况下我需要做什么才能使 Spring Loaded 工作?

最佳答案

我从来没有以这种方式加载 Spring 。就我个人而言,我使用每次都对我有效的“旧方法”。请尝试遵循以下步骤:

在 Eclipse 中打开运行/调试配置。

Debug configuration dialog

在左侧展开“Java 应用程序”选项并选择您的运行配置。 App就我而言。设置错误配置是常见错误,因此请确保projectmain class是正确的。

Main settings

编辑VM arguments并将其设置为 -javaagent:<spring_loaded_jar_file_path> -noverify 。如果您本地没有加载 spring,最简单的获取方法是 checkout their official repo 并运行 ./gradlew .

VM arguments

A gradle build script is included, run './gradlew build' to rebuild the agent - it will be created as something like: springloaded/build/libs/springloaded-1.1.5.BUILD-SNAPSHOT.jar

现在您可以启动新配置。在浏览器中检查内容之前,请检查 eclipse 中的配置。右键单击您的 Java 应用程序并选择属性。

Debug - thread view

然后您应该看到您的应用程序正在使用 javaagent 运行。

JVM properties

请告诉我们这是否适合您。

关于eclipse - Spring Boot、Spring Loaded、Eclipse、Maven 基本示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27718939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com