Reputation: 10149
As following I can change the server port, is there a way to make same thing for actuator management service port.
I know similar ways to change to the via system parameter, adding management.port=XXX into application.properties.
@EnableScheduling
@Configuration
@EnableAspectJAutoProxy
@Profile("dev")
public class AppConfig {
Logger logger = LoggerFactory.getLogger(AppConfig.class);
@Autowired
DBPropertyBean dbPropertyBean;
private @Value("${webserver.port}")
int serverPort;
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(serverPort);
return factory;
}
Upvotes: 3
Views: 919
Reputation: 4476
Yes, If you deep into the sources, for the management.port=XXX
is just auto-confiure the ManagementServerProperties
bean, so with the JavaConfig, just inject the ManagementServerProperties
and config the port. ( As demo, I hardcode all the ports. )
@Configuration
class AppConfig {
private int serverPort = 8081;
@Autowired
private ManagementServerProperties managementServerProperties;
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(serverPort);
if (managementServerProperties != null)
managementServerProperties.setPort(8089);
return factory;
}
}
Upvotes: 2