maven에서 gradle로 변환...

gradle설치 (for macOS) 1 brew install gradle 원래 수동으로 설치하는 방법이 있으나.. 나는 위와 같이 자동 설치를 좋아한다 대부분 그렇지 않을까~ 수동 설치는 사이트에서 참고하자 https://gradle.org/gradle-download/ pom.xml -> build.gradle로 변환 1 2 # 프로젝트 폴더 (pom.xml이 있는곳) 으로 이동 gradle init --type pom 위와 같이 하면 project name 및 dependencies 등이 gralde용 build script로 변환이 되고 프로젝트가 gradle를 사용가능하도록 설정된다 intelliJ IDEA에서 기존 maven으로 구성된 프로젝트라면 module을 새로 import해야 한다 (그래야 툴에서 인식이 되는듯 하다)...

July 14, 2016 · 3 min · 페이퍼

spring jpa namedQuery 직접 호출하기

Test.java에서 처럼 EntityManager를 이용하여 orm.xml에 정의한 NamedQuery를 바로 실행 할 수 있다.. repository를 이용하여 호출하면 getResultList로만 실행되는 것 같다. update 반영된 Row수를 알기 위해 아래와 같이 호출 했다. Test.java 1 2 3 4 5 6 @PersistenceContext private EntityManager em; public void test() { int cnt = em.createNamedQuery("Order.clearOrder").executeUpdate(); logger.info("Order.clearOrder updated={}", cnt); } @PersistenceContext private EntityManager em; 에서.. @PersistenceContext @Autowired 둘다 작동 하는것 같다. 차이는 아직 잘 모르겠다. META-INF/orm.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 <?...

November 13, 2015 · 1 min · 페이퍼

spring redis 연동

pom.xml 에 아래 추가. 1 2 3 4 5 6 7 8 9 10 <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.1.0.RELEASE</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency> 버전을 잘 맞춰야 한다. 안그러면 몇몇 class가 없어서 오류가 발생해요. context-redis.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:usePool="true" p:hostName="172.xxx.xxx.xxx" p:port="6379" /> <!...

November 10, 2015 · 2 min · 페이퍼

spring + sitemesh 웹사이트 구축

sitemesh를 설정을 해보겠습니다. pom.xml 1 2 3 4 5 <dependency> <groupId>opensymphony</groupId> <artifactId>sitemesh</artifactId> <version>2.4.2</version> </dependency> WEB-INF/web.xml 에 아래 추가. 1 2 3 4 5 6 7 8 <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> WEB-INF/sitemesh.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <?xml version="1.0" encoding="UTF-8"?> <sitemesh> <property name="decorators-file" value="/WEB-INF/decorators.xml" /> <excludes file="${decorators-file}" /> <page-parsers> <parser content-type="text/html" class="com....

October 28, 2015 · 3 min · 페이퍼

spring jpa 저장

jpa에서는 저장시 repository.save 함수를 이용하여 저장합니다 Member class처럼 @OneToMany나 @ManyToOne 필드들을 함께 저장 할 수 있습니다. Member.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @Entity @Table(name = "tb_member") public class Member { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "member_seq") public Integer memberSeq; @Column public String nickname; @Expose @OneToMany( targetEntity = MemberInter.class , cascade = CascadeType.ALL , fetch = FetchType....

October 21, 2015 · 2 min · 페이퍼

spring jpa의 @NamedQuery, @NamedNativeQuery 연습

jpa에서.. repository를 이용하여 findAll이나.. findOneBy…. 시리즈를 써서 데이타를 조회 할수 있지만 아래와 같이 특정 쿼리를 직접 입력하여 이용도 가능합니다. /classes/META-INF/orm.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 <?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="2.0"> <named-query name="Inter.findByAlal2"> <query>select i from Inter i where i.internameko = ?1</query> </named-query> <named-native-query name="Inter.findByAlal" result-class="sample.jpa.Inter"> <query>select a.inter_seq, a.inter_name_ko, a.inter_name_en from tb_inter a where a.inter_name_ko = ?</query> </named-native-query> </entity-mappings> 또는.. 아래와 같이 Entity 클래스에 선언해도 됩니다...

October 8, 2015 · 1 min · 페이퍼

spring jpa 조회 연습

entity 작업에 조회까지.. 테스트 해봤습니다. 테이블의 관계가 아래와 같을때 상황 1 tb_member -< tb_member_inter >- tb_inter 조회 조건 Member를 가져오면.. member의 이미지들과… inter의 목록을 함께 가져오도록 inter의 상세 정보는 tb_inter에 있음 (가져올때 조인해서..) 아래 class들 간략 설명 MemberInter의 PK가 두개이므로. 위와 같이 클래스를 하나 만들어서 @IdClass를 지정해야 함 @Expose 는 Gson관련하여 화면에 뿌릴 필드를 정하는 옵션입니다. jpa와는 무관합니다. MemberInter.class에서 많이 헷갈렸습니다. (@ManyToOne) @JoinColumn을 추가로.. 써야 합니다. optional을 true로 하면 join시 outer join을 합니다....

October 7, 2015 · 2 min · 페이퍼

spring jpa 설정 및 테스트 (maven 설정)

거의 대부분 mybatis 를 이용하여 개발을 하는데.. JPA가 대세라고 해서 가벼운 프로젝트에 연동을 해봤습니다. 1. 라이브러리 import…. maven pom.xml 1 2 3 4 5 6 7 8 9 10 <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.9.0.RELEASE</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.8.Final</version> </dependency> 2. Entity class를 만들어 줍니다. 참고로 SerializedName, Expose는 jpa와 직접 관련은 없습니다.. (개체를 그대로 JsonView 할때 사용) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 import com....

October 5, 2015 · 3 min · 페이퍼

spring batch 사용

최근에 spring-batch를 사용해 봤는데.. 결과는 성공적 특히 트랜잭션commit size와 read size를 따로 지정할 수 있다는게 좋은것 같다. 쿼리나 기타 로직보다 아래 설정이 중요한 듯 하여 아래 설정을 기록으로 남긴다. job에 대해서 요약하면 reader에서 데이타를 읽어서 process 에서 처리 하고 writer로 결과를 기록 한다. 물론 위 설정 외에 각 시작 구간마다 이벤트를 받아 처리 할 수 있는 listener 같은 것도 제공한다. reader, writer는 커스텀 하지 않고 mybatis에서 기본으로 제공하는 걸 이용했다....

August 27, 2015 · 1 min · 페이퍼

하둡 스프링 연동 테스트2 - hadoop 2.6.x with spring 4.0 (MapReduce WordCount example)

context-hadoop.xml에 아래 내용 추가. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <hdp:configuration id="hdConf"> fs.default.name=hdfs://localhost:9000 </hdp:configuration> <hdp:job id="wordCountJob" input-path="/input/" output-path="/output/" configuration-ref="hdConf" mapper="delim.app.service.WordCount$TokenizerMapper" reducer="delim.app.service.WordCount$IntSumReducer" > </hdp:job> <hdp:job-runner id="wordCountJobRunner" job-ref="wordCountJob" run-at-startup="false"> </hdp:job-runner> WordCount.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 import org....

April 15, 2015 · 2 min · 페이퍼