简体   繁体   English

如何覆盖spring-boot的配置?

[英]How to override spring-boot's configuration?

I'm using spring-boot-starter-web with spring-boot-starter-jetty and I would like to be able to change Jetty's config by injecting my own xml bean. 我使用带有spring-boot-starter-jetty spring-boot-starter-web ,我希望能够通过注入自己的xml bean来更改Jetty的配置。 I cannot figure out how to override the configuration in spring-boot-starter-jetty. 我无法弄清楚如何在spring-boot-starter-jetty中覆盖配置。

Here's a part of my pom.xml 这是我的pom.xml的一部分

<dependencies>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
</dependencies>

Here's how the application starts 这是应用程序启动的方式

@SpringBootApplication
public class Application {

        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
}

I create a bean in a file named jetty.xml to override the port for Jetty 我在名为jetty.xml的文件中创建一个bean,以覆盖Jetty的端口。

<bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
        <constructor-arg ref="server"/>
        <property name="port" value="8789"/>
</bean>

Then I thought by importing this resource, it would override the port in spring-boot 然后我想通过导入此资源,它将覆盖spring-boot中的端口

@Configuration  
@ImportResource( { "classpath*:jetty.xml" } )  
public class ConfigJetty { } 

but the port stays at 8080 但港口停留在8080

How can we achieve this? 我们怎样才能做到这一点?

Thank you 谢谢

'In a standalone application the main HTTP port defaults to 8080, but can be set with server.port (eg in application.properties or as a System property). '在独立应用程序中,主HTTP端口默认为8080,但可以使用server.port进行设置(例如,在application.properties中或作为System属性)。 ' '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM