Refactor to clense task name
When using Spring Boot, the id of the application context can be a colon delimited string of values. By default, Spring Cloud Task uses this value as the task name. However, when using JMX, this can cause issues. This commit updates the SimpleTaskNameResolver to clense the colons and replace them with underscores. Resolves #280
This commit is contained in:
committed by
Glenn Renfro
parent
fec40fd3f8
commit
ac41b8c26d
@@ -55,7 +55,7 @@ public class SimpleTaskNameResolver implements TaskNameResolver, ApplicationCont
|
||||
return configuredName;
|
||||
}
|
||||
else {
|
||||
return context.getId();
|
||||
return context.getId().replace(":", "_");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@@ -37,6 +37,17 @@ public class SimpleTaskNameResolverTests {
|
||||
assertTrue(taskNameResolver.getTaskName().startsWith("org.springframework.context.support.GenericApplicationContext"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithProfile() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.setId("foo:bar");
|
||||
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertTrue(taskNameResolver.getTaskName().startsWith("foo_bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationName() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
Reference in New Issue
Block a user