feat(config): 增加PowerJobWorker端口配置支持

- 从属性文件读取powerjob.worker.port配置项
- 将端口号设置为读取的配置值,替代随机生成
- 优化PowerJobWorker初始化,提升配置灵活性
- 修复配置类导入的无用scala.Int依赖问题
This commit is contained in:
曹鹏飞 2026-05-09 14:27:07 +08:00
parent 529ab9ac20
commit c3738f4f55
1 changed files with 5 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import scala.Int;
import tech.powerjob.common.enums.Protocol;
import tech.powerjob.worker.PowerJobSpringWorker;
import tech.powerjob.worker.common.PowerJobWorkerConfig;
@ -19,11 +20,14 @@ public class PowerJobWorkerConfiguration {
@Value("${powerjob.worker.server-address}")
private String severAddress;
@Value("${powerjob.worker.port}")
private int port;
@Bean
public PowerJobSpringWorker initPowerJobWorker() {
PowerJobWorkerConfig config = new PowerJobWorkerConfig();
config.setAppName(appName);
config.setPort(RandomUtil.randomInt(10000, 20000));
config.setPort(port);
config.setServerAddress(StrUtil.split(severAddress, ","));
config.setProtocol(Protocol.HTTP);
// 如果没有大型 Map/MapReduce 的需求建议使用内存来加速计算