728x90
반응형
docker-compose.yml
version: '3'
services:
mysql:
image: mysql:5.7
container_name: feed_service_mysql
ports:
- "3400:3306"
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=sns_feed
- MYSQL_USER=sns_feed
- MYSQL_PASSWORD=1234
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 10s
retries: 10
restart: always
volumes:
- /Users/Shared/data/mysql-test:/var/lib/mysql
참고: 위의 동작이 실행되지 않을 경우.
- MYSQL_USER와 MYSQL_PASSWORD를 사용하기 위해 새로운 User를 만들어 준다.
- workbench를 이용해 docker의 mysql로 접속한 뒤 다음 명령을 실행한다.
create user 'sns_feed'@'%' identified by '1234';
grant all privileges on *.* to 'sns_feed'@'%';
flush privileges;
docker-compose 실행
- docker-compose up
yml
- application.yml
server.port: 3000
spring:
profiles:
include: mysql
- application-mysql.yml
spring:
datasource:
url: jdbc:mysql://localhost:3400/sns_feed?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul
username: sns_feed
password: 1234
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
driver-class-name: com.mysql.cj.jdbc.Driver
jackson:
property-naming-strategy: SNAKE_CASE
jpa:
hibernate:
ddl-auto: update
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
테스트
- FeedEntity
@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Table(name = "feed")
public class Feed {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
private String content;
private Long userId;
}
- FeedRepository
public interface FeedRepository extends JpaRepository<Feed, Long> {
}
- FeedrepositoryTest
@SpringBootTest
class FeedRepositoryTest {
@Autowired
private FeedRepository feedRepository;
@Test
public void create(){
Feed feed = Feed.builder()
.id(1L)
.title("testTitle")
.content("testContent")
.userId(1L)
.build();
System.out.println(feed);
feedRepository.save(feed);
}
}
파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음
반응형
'Spring' 카테고리의 다른 글
[유효성검증] Spring Boot Validation (0) | 2023.04.14 |
---|---|
Mustache로 템플릿 메일 발송 (0) | 2022.04.26 |
[Spring AOP] AOP를 이용한 Decode (0) | 2021.08.28 |
[Spring Interceptor] 커스텀 어노테이션과 Intercepter 구현 (0) | 2021.08.27 |
[Spring] Filter, Interceptor, AOP (0) | 2021.08.09 |