相关疑难解决方法(0)

没有tomcat嵌入式的spring boot war

我想创建一个没有嵌入式tomcat和maven的war文件.这是我的pom的相关部分

...
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.6.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- Add tomcat only if I want to run directly -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </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)

如果我运行mvn包我得到一个战争,其中tomcat*.jar在提供的lib文件夹中,但仍然在lib文件夹中.我读了build-tool-plugins-maven-packaging,但找不到什么问题.

我知道一个主要的想法是将其作为一个应用程序运行,我们的客户希望如何将其部署在他的应用程序服务器上.

spring war maven spring-boot

24
推荐指数
4
解决办法
5万
查看次数

关于spring boot如何正确禁用web环境

Spring启动非Web应用程序,启动时有以下错误

Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
Run Code Online (Sandbox Code Playgroud)

然后我尝试了下面的方式

new SpringApplication().setWebEnvironment(false);
Run Code Online (Sandbox Code Playgroud)

然后开始它仍然有上面的错误.

然后试过

@SpringBootApplication(exclude={SpringDataWebAutoConfiguration.class})
Run Code Online (Sandbox Code Playgroud)

但仍然有同样的错误.

最后我尝试添加以下配置 application.properties

spring.main.web-environment=false
Run Code Online (Sandbox Code Playgroud)

这次它有效.

为什么前两种方式不起作用?

spring-boot

9
推荐指数
2
解决办法
2万
查看次数

Spring执行器可以与非Web Spring Boot应用程序一起使用吗?

我有一个Spring Boot应用程序,它监听来自IBM MQ输入队列的消息,对消息进行一些处理,然后将消息放入输出队列.

像这样的应用可以利用Spring执行器来监控应用(例如心跳检查)吗?从阅读执行器文档,它似乎只能用于Spring Web应用程序?我的理解不正确吗?如果是这样,您能否提供有关如何在非Web应用程序中使用执行器的信息?

java spring-jms spring-boot spring-boot-actuator application-monitoring

5
推荐指数
1
解决办法
1729
查看次数

如何在春季启动时禁用http服务器?

Spring启动文档声称设置server.port = -1会禁用http端点,但对我而言,它的行为与我使用port = 0的行为相同.我想要实现的是批量弹簧启动应用程序,它启动,执行某些操作并关闭.现在它只是坐在那里直到我杀了它.

如何防止它启动http服务器?或者 - 如何从代码中优雅地关闭Spring启动应用程序?

我使用的是版本1.2.4.RELEASE.我在主类上有以下注释:

@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableCaching
Run Code Online (Sandbox Code Playgroud)

编辑 - 我的依赖项:

compile(
    'redis.clients:sharded-jedis-sentinel-pool:0.2.10.08e7bbe',
    'org.springframework.boot:spring-boot-starter-jdbc',
    'org.springframework.boot:spring-boot-starter-web',
    'mysql:mysql-connector-java:5.1.33',
    'org.flywaydb:flyway-core:3.2.1',
)
Run Code Online (Sandbox Code Playgroud)

没有spring-boot-starter-web spring throws:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.GzipFilterAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.GzipFilterProperties org.springframework.boot.autoconfigure.web.GzipFilterAutoConfiguration.properties; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.gzip.CONFIGURATION_PROPERTIES': Initialization of bean failed; nested exception is java.lang.TypeNotPresentException: Type org.springframework.http.HttpMethod not present
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at …
Run Code Online (Sandbox Code Playgroud)

configuration spring spring-boot

3
推荐指数
2
解决办法
4217
查看次数

如何禁用 Spring Web MVC

嗨,我刚刚将 springboot 从 2.0.5 升级到 2.1.8 首先我收到了这个错误

The bean 'requestMappingHandlerAdapter', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class], could not be registered. A bean with that name has already been defined in org.springframework.web.reactive.config.DelegatingWebFluxConfiguration and overriding is disabled.
Run Code Online (Sandbox Code Playgroud)

所以,我添加了这个 application.properties

spring.main.allow-bean-definition-overriding: true
Run Code Online (Sandbox Code Playgroud)

但是我得到了不同的错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.reactive.config.DelegatingWebFluxConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalStateException: The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, e.g. via @EnableWebMvc and @EnableWebFlux, in the same application.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-boot spring-webflux

0
推荐指数
1
解决办法
3880
查看次数