Can I use a message bundle in a file outside the resource path? I mean an external message bundle that can be modified without rebuilding the jar and could be loaded during startup or hot-deploy ?
Yes you can load message property files from any location.
Create an implementation of the io.jmix.core.Resources
interface:
package com.company.demo;
import io.jmix.core.Resources;
import org.springframework.core.io.Resource;
import javax.annotation.Nullable;
import java.io.InputStream;
public class MyResources implements Resources {
private final Resources delegate;
public MyResources(Resources delegate) {
this.delegate = delegate;
}
@Nullable
@Override
public InputStream getResourceAsStream(String location) {
return delegate.getResourceAsStream(location);
}
@Nullable
@Override
public String getResourceAsString(String location) {
return delegate.getResourceAsString(location);
}
@Override
public Resource getResource(String location) {
// this method is used to load messages.properties files
return delegate.getResource(location);
}
@Override
public ClassLoader getClassLoader() {
return delegate.getClassLoader();
}
}
Define the MessageSource
bean accepting MyResources
instead of the standard implementation:
@SpringBootApplication
public class DemoApplication {
// ...
@Bean
MessageSource messageSource(JmixModules modules, Resources resources) {
return new JmixMessageSource(modules, new MyResources(resources));
}
}
1 Like