未分類

aws s3

同一パッケージに配置するMvcConfigクラスでは、HTMLやCSSなどの静的リソースのURLと実際のリソースの物理配置の対応づけの定義をResourceHandlerRegistryに追加し、Controller、Helperクラスを読み取るために、ComponentScanアノテーションに該当のパッケージを指定しておきます。また今回は、S3から取得した画像ファイル、およびテキストデータを返却するので、必要なMessageConverterを追加します。

package org.debugroom.mynavi.sample.aws.s3.config;

// omit

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.BufferedImageHttpMessageConverter;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@ComponentScan(“org.debugroom.mynavi.sample.aws.s3.app.web”)
@Configuration
public class MvcConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(“/static/**”)
.addResourceLocations(“classpath:/static/”);
}

@Override
public void configureMessageConverters(List> converters) {
converters.add(new BufferedImageHttpMessageConverter());
converters.add(byteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
}

@Bean
public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() {
ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
arrayHttpMessageConverter.setSupportedMediaTypes(getSupportedMediaTypes());
return arrayHttpMessageConverter;
}

private List getSupportedMediaTypes() {
List list = new ArrayList();
list.add(MediaType.IMAGE_JPEG);
list.add(MediaType.IMAGE_PNG);
list.add(MediaType.APPLICATION_OCTET_STREAM);
return list;
}

}

……………………………………………………

@Configuration
public class S3Config {

@Bean
public AmazonS3 amazonS3(){
return AmazonS3ClientBuilder.standard().build();
}

}

……………………………………………………

関連記事

  1. サイト診断

  2. 家事記事項目

  3. 意識調査

  4. ライティング

  5. タブ・スライダー

  6. 靴 ブランド

コメント

  1. この記事へのコメントはありません。

  1. この記事へのトラックバックはありません。

おすすめ記事

  1. 家事記事項目

    2019.04.14

  2. ライティング

    2018.10.24

PAGE TOP