小编Cor*_*eyS的帖子

添加Spring Boot应用程序的上下文路径

我试图以编程方式设置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)

java spring spring-mvc spring-boot

148
推荐指数
8
解决办法
27万
查看次数

使用Carrierwave和Ruby重新创建版本

我正在研究的网站正在进行重新设计,因此我们的用户图像需要重新调整大小.该网站目前正在使用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)

amazon-s3 ruby-on-rails-3 carrierwave

8
推荐指数
2
解决办法
1万
查看次数