我有一个Spring Boot应用程序,我已经创建了一个Jar.以下是我的pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- WebJars -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我想在我的其他应用程序中使用此Jar,因此将此jar添加到我的应用程序中.但是,当我在那个Jar中调用一个方法时,它正在抛出一个ClassNotFoundException.
我该如何解决这个问题?如何向Spring Boot JAR添加依赖项?
我正在尝试将属性从pom.xml加载到application.properties中.我想创建两个配置文件:dev和prod以使用不同的数据库URL.我在我的所有应用程序中使用Jenkins作为CI(主要是Spring MVC,没有Boot项目)正在使用maven配置文件部署到Tomcat.使用maven属性有可能做到这一点吗?我试过这样的事情:
spring.datasource.url=${jdbc.url}
我正在使用部署到 AWS BeanStalk 的 spring-boot-maven-plugin 构建 Docker 映像。我通过 2.4.3 spring boot starter 依赖项使用该插件)但是,当容器启动时,我收到以下错误。我对 buildpack 的东西有点陌生,但尝试通过使用网站上描述的 Buildpack 环境变量来解决它。但它对下面错误日志中显示的值完全没有影响。我发现了这个github问题,但不确定它是否相关以及如何使用它。
我正在使用总 RAM 为 1G 的 AWS Micro 实例,它执行滚动更新,因此在启动新映像时,另一个也在运行,直到新映像成功启动,因此启动容器也可以是只有 300MB 可用,但是,在正常运行期间,它还有更多可用空间。
为什么我需要这个内存计算?我不能直接禁用它吗?当我构建 app.jar 的 Docker 映像并将其部署到 aws beanstalk 时,它无需任何内存设置即可正常运行:
码头工人构建。--build-arg JAR_FILE=./target/app.jar -t $APPLICATION_NAME
但我很想通过 spring-boot-maven 插件使用图像构建。请提供有关如何解决此问题的建议?
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>${image.name}</name>
<env>
<tag>${project.version}</tag>
<!--BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=1M</BPE_APPEND_JAVA_TOOL_OPTIONS-->
<BPE_JAVA_TOOL_OPTIONS>-Xms1024m -Xmx3048m</BPE_JAVA_TOOL_OPTIONS>
</env>
</image>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
部署期间 AWS Beanstalk 错误:
Tue May 18 2021 18:07:14 GMT+0000 (UTC) INFO Successfully built aws_beanstalk/staging-app
Tue May 18 2021 18:07:22 GMT+0000 …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-elastic-beanstalk spring-boot-maven-plugin paketo
想象一下多模块maven项目.项目结构是:
pom.xml //parentpom
|
pom.xml //submodule_1
|
pom.xml //submodule_2
.
.
.
pom.xml //submodule_7
Run Code Online (Sandbox Code Playgroud)
例如,submodule_5将submodule_6和submodule_7作为依赖项.可以构建submodule_5以构建可以部署的War文件.只要submodule_5的类路径发生变化,Spring-Boot-Devtools就会提供自动重启功能.
每当使用以下命令运行应用程序时:
mvn spring-boot:run
Run Code Online (Sandbox Code Playgroud)
并且对submodule_5进行了更改(取决于您使用类路径的IDE更改.(对于Eclipse自动/对于InteliJ,当按Ctrl+时F9))spring-boot自动重启应用程序并添加更改.发生在submodule_6或submodule_7上的更改不会触发自动重启.
我在stackoverflow上看到了很多关于此的问题.但是我仍然无法知道建设项目的方式是什么问题.
我有两个春季启动项目:we-data和we-web.we-web依赖于we-data.we-data在maven上编译得很好.但是我们网络给了我上面的错误.
我们数据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.we</groupId>
<artifactId>data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>we-data</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
we-web 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.we</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>we-web</name>
<description>Demo project for Spring …Run Code Online (Sandbox Code Playgroud) 我使用Spring-Boot v1.3.0.M5和Maven v3.3.3.我曾经能够使用此命令从控制台运行我的Spring Boot(启动)应用程序.
mvn clean package spring-boot:run
但是,我不得不修改我pom.xml的帐户以适应不同的环境构建.特别是,我使用Maven配置文件来修改启动应用程序的属性文件.现在,当我运行前面提到的命令时,启动应用程序无法运行并抱怨以下异常.
引起:java.lang.NumberFormatException:对于输入字符串:"$ {MULTIPART.MAXREQUESTSIZE}"
我有一个属性文件位于src/main/resources/config/application.properties.此属性文件有一堆键值对,如下所示.
multipart.maxFileSize=${multipart.maxFileSize}
multipart.maxRequestSize=${multipart.maxRequestSize}
Run Code Online (Sandbox Code Playgroud)
然后在我的pom.xml,我的构建定义如下.
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<!-- development -->
<profile>
<id>env-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<properties>
<multipart.maxFileSize>250MB</multipart.maxFileSize>
<multipart.maxRequestSize>250MB</multipart.maxRequestSize>
</properties>
</profile>
<!-- staging -->
<profile>
<id>env-stg</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>stg</value>
</property>
</activation>
<properties>
<multipart.maxFileSize>500MB</multipart.maxFileSize>
<multipart.maxRequestSize>500MB</multipart.maxRequestSize>
</properties>
</profile> …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我想使用特定于环境的属性文件.例如,如果我将它运行到开发中,它应该使用application.dev.properties,对于生产它应该使用application.prod.properties等.
我的资源文件夹下面有两个文件.
我在每个文件中都有一个如下所示的属性.
对于产品
server.database.host=192.168.1.1
Run Code Online (Sandbox Code Playgroud)
对于开发
server.database.host=192.168.12.125
Run Code Online (Sandbox Code Playgroud)
我有一个类似下面的课程
public class DataSource {
@Value(${server.database.host})
String host;
Run Code Online (Sandbox Code Playgroud)
上面的代码总是需要prod设置(application.properties)文件,即使我为dev提供适当的参数 --spring.profiles.active=dev
下面是我用来加载dev属性文件的命令.
java -jar myjar.jar --spring.profiles.active=dev
Run Code Online (Sandbox Code Playgroud)
它还打印出活动配置文件是dev,但它始终连接到prod db.
我正在使用spring-boot-maven-plugin我的REST服务打包.我正在用mvn clean install或建造罐子mvn clean package.在我反编译jar之后,我没有发现添加任何依赖项(我希望它是一个包含所有依赖项的胖jar)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<finalName>myapp</finalName>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我运行spring boot时,java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal"我正在为许多类获取ClassNotFoundException.很明显,工件没有像预期的那样构建.但是,如果我使用maven启动spring boot应用程序,./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal"我猜它会找到目标文件夹中的所有依赖项,因此工作正常.如何修复构建问题,以便我可以使用java -jar命令启动应用程序.
编辑:这是多模块maven项目
我是 springboot 的新手,使用的是 springboot 2 版本。
我想在命令提示符下使用java -jar my-app-0.0.1-SNAPSHOT.jar运行我的 spring boot 应用程序。
但是,当我使用 eclipse 构建应用程序时,它直接调用 myService.getMyMethod() 并且不构建 jar。
我想先构建 jar 文件,然后从命令提示符运行java -jar my-app-0.0.1-SNAPSHOT.jar ,这将调用 myService.getMyMethod()
我已经在 pom.xml 中有 spring-boot-maven-plugin,运行mvn package / mvn install启动应用程序,但不会在目标文件夹中生成 jar 文件。mvn clean package 也不起作用,MyApplication 正在使用实现 CommandLineRunner 并开始调用构建方法,因此不生成构建 jar 文件
我的主要课程:
@SpringBootApplication
public class MyApplication implements CommandLineRunner {
private static String URL = "ws://localhost:8080/spring-mvc-java/chat";
@Autowired
private MyService myService;
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Override
public void run(String... args) throws …Run Code Online (Sandbox Code Playgroud) java pom.xml spring-boot spring-websocket spring-boot-maven-plugin
我有一个非常标准的Spring Boot应用程序(application.properties属性文件位于标准/src/main/resources文件夹中),我将其作为"胖JAR"部署在AWS Elastic Beanstalk上.它工作得很好,但是服务器上的图像上传存在问题.经过一些调查后,似乎需要调整NGINX配置(增加到client_max_body_size可以接受上传的内容10MB),因此我添加了一个带有以下内容的文件.ebextensions夹/src/main/resources(取自此答案): -
files:
"/etc/nginx/conf.d/proxy.conf":
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
Run Code Online (Sandbox Code Playgroud)
但是,当我运行mvn我的构建时,它不会.ebextensions在根文件夹中创建,我想知道什么是最佳解决方案.我的pom.xml文件很小,目前包含以下内容:
...
<packaging>jar</packaging>
....
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
@Lorena当我<resources> ...向我插入XML pom.xml然后启动服务器时,它崩溃了以下内容: -
2017-03-20 21:40:29.504 WARN 10784 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: …Run Code Online (Sandbox Code Playgroud) spring-boot amazon-elastic-beanstalk spring-boot-maven-plugin