도커 컨테이너 종료 

$ docker stop 컨테이너id

 

도커 컨테이너 실행 

$docker exec 컨테이너id

 

실행중인 컨테이너 확인
$docker ps

 

전체 컨테이너 확인
$docker ps -a

 

컨테이너 삭제
$docker rm 컨테이너id

 

도커 이미지 확인
$docker images

 

도커 이미지 지우기
$docker rmi 이미지id

 

컨테이너 삭제, 이미지 삭제 동시
$docker rmi -f 이미지id

 

참고: https://brunch.co.kr/@hopeless/10

fastcampus Java SpringCore 강좌를들으면서 정리를 하였습니다.

ClassPath Scanning

특정 classpath 이하에 있는 관리할 컴포넌트(@Component)들을 등록을 하기 위해 스캔함

@Component : Annotation Type으로 런타임에 동작함. classpath scanning을 통해 자동적으로 검색됨.

@Repository, @Service, @Controller

@ComponentScan(basePackages = "kr.co.fastcampus.cli") 을 해주면 xml에 별도로 설정을 안해줘도 알아서 추가가 됨.

예시

@Configuration
@ComponentScan(basePackages = "kr.co.fastcampus.cli")
public class AppConfig {
    @Bean
    public A a1(){
        return new A();
    }
    @Bean
      @Scope("singleton")
    public B b1(){
        return new B();
    }
}

@Component
class A {}

@Component
class B{}

아래와 같이 AnnotationConfigApplicationContext()를 사용해서 사용이 가능하다.

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

AnnotationConfigApplicationContext API 를 살펴보면 아래와 같이 파라미터를 넣어주면 사용이 가능하다.

Constructor and Description
AnnotationConfigApplicationContext()Create a new AnnotationConfigApplicationContext that needs to be populated through register(java.lang.Class...) calls and then manually refreshed.
AnnotationConfigApplicationContext(Class... componentClasses)Create a new AnnotationConfigApplicationContext, deriving bean definitions from the given component classes and automatically refreshing the context.
AnnotationConfigApplicationContext(DefaultListableBeanFactory beanFactory)Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
AnnotationConfigApplicationContext(String... basePackages)Create a new AnnotationConfigApplicationContext, scanning for components in the given packages, registering bean definitions for those components, and automatically refreshing the context.

Filter

ComponentScan에서 특정 클래스를 빼고 싶을 때, (pattern, class, 등 의 다양함 )

아래처럼 filter를 사용해서 execludeFilters를 사용하여 가능하다.

@Slf4j
@ComponentScan(basePackageClasses = Main.class , excludeFilters = @ComponentScan.Filter (type= FilterType.REGEX,pattern="kr.co.fastcampus.cli.B"))
public class Main {
    static Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String []args) {

        //Java Anotation을 사용한 주입
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Main.class);
        B b = context.getBean(B.class);
        log.info("b : "+b);
        context.close();
    }
}

ComponentScan 성능 향상

ComponentScan은 Java Generic을 사용하여 JVM에서 어노테이션이 붙어있는지 아닌지 결정하여 판단을 하게 되는데, 만약 어노테이션이 너무 많이 사용되게 되면 ComponentScan이 오래 걸릴 수 있다.

그래서 indexer를 만들어 놓음

pom.xml에 추가

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-indexer</artifactId>
        <version>5.2.3.RELEASE</version>
        <optional>true</optional>
    </dependency>
</dependencies>

빌드를 하게 되면 META-INF/spring.components 가 만들어짐.

'BackEnd > Spring' 카테고리의 다른 글

ClassPath Scanning and Managed Components  (0) 2020.02.22
Bean Scope  (0) 2020.02.11
Customizing the Nature of a Bean  (0) 2020.02.01
DI (Dependency Injection)  (0) 2020.02.01
Spring-Core  (0) 2020.01.19

SparkSession

모든 스파크 애플리케이션은 가장 먼저 SparkSession을 생성

기존 코드 : new SparkContext 패턴을 사용 (과거 SparkContext, SQLContext 를 직접 생성)

최신 코드 : SparkSession의 빌더 메서드를 사용해 생성할것을 추천

SparkSession 클래스는 스파크2.x 버전 에서 사용이 가능하다

new SparkContext 에서 보다 안전하게 생성할 수 있다. 다수의 라이브러리가 세션을 생성하려는 상황에서 컨텍스트 충돌을 방지 할 수 있다.

예제

val spark = SparkSession.builder
.appName("My Spark Application")  // optional and will be autogenerated if not specified
.master("local[*]")      // only for demo and testing purposes, use spark-submit instead
.enableHiveSupport()              // self-explanatory, isn't it?
.config("spark.sql.warehouse.dir", "target/spark-warehouse")
.config("spark.som.config.option","some-value")
.getOrCreate()



SparkSession, SQLContext, HiveContext

과거 버전의 스파크에서는 SQLContext와 HiveContext를 사용해 DataFrame과 스파크 SQL을 다룰수 있었음.
과거 SparkContext는 스파크의 핵심 추상화 개념을 다루는데 중점을 두고 , SQLContext는 스파크의 핵심 추상화 개념을 다루는데 중점을 둠 
Spark2.x 이후 부터는 두 콘텍스트를 SparkSession으로 단일화함
SparkContext, SQLContext는 존재하지만 SparkSession을 통하여 접근이 가능하다.

멀티 세션

newSession

SparkContext를 공유하고 session 만 달라지는 방법, 개별의 session 마다 동일한 이름의 테이블 생성 가능.

동일한 jvm에 여러개의 스파크 컨텍스트를 갖는것은 권장되지 않으며 더 불안하고 하나의 스파크 컨텍스트가 충돌하면 다른 스파크에 영향을 줄수 있다.

newSession으로 만들어진 세션중 하나라도 stop/close 를 하게 되면 동일한 SparkContext를 사용하기 때문에 종료가 된다.

sparkSession.newSession();

 

 

참고

Spark 완벽 가이드(도서)

Spark -newSession (https://medium.com/@achilleus/spark-session-10d0d66d1d24)

SparkSession - The Entry Point to Spark SQL (https://jaceklaskowski.gitbooks.io/mastering-spark-sql/spark-sql-SparkSession.html)

+ Recent posts