我试图以编程方式设置Spring Boot应用程序上下文根.上下文根的原因是我们希望从中访问应用程序localhost:port/{app_name}并将所有控制器路径附加到它.
这是web-app的应用程序配置文件.
@Configuration
public class ApplicationConfiguration {
Logger logger = LoggerFactory.getLogger(ApplicationConfiguration.class);
@Value("${mainstay.web.port:12378}")
private String port;
@Value("${mainstay.web.context:/mainstay}")
private String context;
private Set<ErrorPage> pageHandlers;
@PostConstruct
private void init(){
pageHandlers = new HashSet<ErrorPage>();
pageHandlers.add(new ErrorPage(HttpStatus.NOT_FOUND,"/notfound.html"));
pageHandlers.add(new ErrorPage(HttpStatus.FORBIDDEN,"/forbidden.html"));
}
@Bean
public EmbeddedServletContainerFactory servletContainer(){
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
logger.info("Setting custom configuration for Mainstay:");
logger.info("Setting port to {}",port);
logger.info("Setting context to {}",context);
factory.setPort(Integer.valueOf(port));
factory.setContextPath(context);
factory.setErrorPages(pageHandlers);
return factory;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = …Run Code Online (Sandbox Code Playgroud) 我正在研究的网站正在进行重新设计,因此我们的用户图像需要重新调整大小.该网站目前正在使用carrierwave gem处理所有图像和视频处理,每个图像都有一个原始文件,其文件名基于以下内容:
def filename
if original_filename
if model && model.read_attribute(:user_image).present?
model.read_attribute(:user_image)
else
@name ||= "#{secure_token}.#{file.extension}" if original_filename.present?
end
end
end
Run Code Online (Sandbox Code Playgroud)
和secure_token由.生成
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
Run Code Online (Sandbox Code Playgroud)
为此执行创建的任务是:
##
# CarrierWave Amazon S3 File Reprocessor Rake Task
#
# Written (specifically) for:
# - CarrierWave
# - Ruby on Rails 3
# - Amazon S3
#
# Works with:
# - Any server of which you have write-permissions in the Rails.root/tmp directory
# - Works with …Run Code Online (Sandbox Code Playgroud)