我正在使用 maven 依赖项在另一个 spring boot 项目中使用 spring boot 项目(jar)。jar 文件在 application.properties 中没有定义属性,我想在 jar 文件中获取当前 spring boot 项目的属性。有没有办法覆盖jar的application.properties。
===============微服务1======================:
@SpringBootApplication
@ComponentScan({"com.jwt.security.*"})
public class MicroserviceApplication1 {
public static void main(String[] args) throws Exception {
SpringApplication.run(MicroserviceApplication1.class, args);
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}
应用程序属性
jwt.auth.secret: secret
jwt.auth.token_prefix : Bearer
jwt.auth.header_string : Authorization
用户控制器
@RestController
@Slf4j
public class UserController
{
@RequestMapping(value="/jwt")
public String tokens(){
log.debug("User controller called : Token()");
return "successful authentication";
}
}
pom.xml
...
<dependency>
<groupId>com.jwt.security</groupId>
<artifactId>securityUtils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
现在,下面是 jar 中的配置。
==========securityUtils=============
@Slf4j
@Component
//@PropertySource("classpath:/application.properties")
//@ConfigurationProperties(prefix = "jwt")
class TokenAuthenticationService {
@Value("${jwt.auth.secret}")
private static String secret;
@Value("${jwt.auth.header_string}")
private static String headerString;
@Value("${jwt.auth.token_prefix}")
private static String tokenPrefix;
static void getAuthentication(HttpServletRequest request) {
String token = request.getHeader(headerString);
Date referenceTime = new Date();
if (token != null) {
final Claims claims = Jwts.parser()
.setSigningKey(secret.getBytes())
.parseClaimsJws(token.replace(tokenPrefix, ""))
.getBody();
if (claims == null) {
throw new BadCredentialsException("You are not authoriozed");
} else {
Date expirationTime = claims.getExpiration();
if (expirationTime == null || expirationTime.before(referenceTime)) {
log.debug("The token is expired");
throw new TokenExpiredException("The token is expired");
}
}
} else {
throw new BadCredentialsException("You are not authoriozed");
}
}
}
在 TokenAuthenticationService 我想获取从调用微服务加载的属性1
谢谢