NCP CFR(Clova Face Recognition) API를 활용한 Extension Kit 개발 소스입니다.
개발 소스 설명 GitBook : https://mysm0722.gitbooks.io/my-project-book/content/
NCP CFR(Clova Face Recognition) API를 활용한 Extension Kit 개발 소스입니다.
개발 소스 설명 GitBook : https://mysm0722.gitbooks.io/my-project-book/content/
springdataneo4j
)spring-boot-starter-data-neo4j
(pom.xml)
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
...
$ docker run -p 7474:7474 -p 7687:7687 -d--name noe4j_boot neo4j
http://localhost:7474/browser
neo4j/neo4j
임(application.properties)
spring.data.neo4j.password=1111
spring.data.neo4j.username=neo4j
(Neo4jRunner.java)
package me.darrel.springdataneo4j;
import me.darrel.springdataneo4j.account.Account;
import me.darrel.springdataneo4j.account.Role;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Component
public class Neo4jRunner implements ApplicationRunner {
@Autowired
SessionFactory sessionFactory;
@Override
public void run(ApplicationArguments args) throws Exception {
Account account = new Account();
account.setEmail("[email protected]");
account.setUsername("general");
Role role = new Role();
role.setName("admin");
account.getRoles().add(role);
Session session = sessionFactory.openSession();
session.save(account);
sessionFactory.close();
System.out.println("Finished");
}
}
(Account.java)
package me.darrel.springdataneo4j.account;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import java.util.HashSet;
import java.util.Set;
@NodeEntity
public class Account {
@Id @GeneratedValue
private Long Id;
private String username;
private String email;
@Relationship(type = "has")
private Set<Role> roles = new HashSet<>();
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
(Role.java)
package me.darrel.springdataneo4j.account;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
@NodeEntity
public class Role {
@Id @GeneratedValue
private Long Id;
private String name;
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
애플리케이션을 실행하면 아래와 같이 Neo4j에 Releationship을 가진 테이블이 생성됨
위의 애플케이션을 Neo4jRepository
를 사용하여 변경함
(Neo4jRunner.java)
package me.darrel.springdataneo4j;
import me.darrel.springdataneo4j.account.Account;
import me.darrel.springdataneo4j.account.AccountRepository;
import me.darrel.springdataneo4j.account.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Component
public class Neo4jRunner implements ApplicationRunner {
@Autowired
AccountRepository accountRepository;
@Override
public void run(ApplicationArguments args) throws Exception {
Account account = new Account();
account.setEmail("[email protected]");
account.setUsername("user");
Role role = new Role();
role.setName("user");
account.getRoles().add(role);
accountRepository.save(account);
System.out.println("Finished");
}
}
(AccountRepository.java)
package me.darrel.springdataneo4j.account;
import org.springframework.data.neo4j.repository.Neo4jRepository;
public interface AccountRepository extends Neo4jRepository<Account, Long> {
}
애플리케이션을 실행하면 아래와 같이 Neo4j에 Releationship을 가진 테이블이 생성됨
Neo4jTemplate (Deprecated)
Neo4jRepository
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-sql
UserDetailsService
를 생성하여 빈으로 등록하면 됨https://docs.spring.io/spring-security/site/docs/current/reference/html5/#test
springbootsecurity
, Web 모듈만 추가)기본적인 Controller/Templates/Test코드를 작성함
(HomeController.java)
package me.darrel.springbootsecurity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/hello")
public String hello() {
return "hello";
}
@GetMapping("/my")
public String my() {
return "my";
}
}
(HomeControllerTest.java)
package me.darrel.springbootsecurity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
@RunWith(SpringRunner.class)
@WebMvcTest
public class HomeControllerTest {
@Autowired
MockMvc mockMvc;
@Test
public void hello() throws Exception {
mockMvc.perform(get("/hello"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("hello"));
}
@Test
public void my() throws Exception {
mockMvc.perform(get("/my"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("my"));
}
}
(~/templates/index.html)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>Welcome</h1>
<a href="/hello">Hello</a>
<a href="/my">My</a>
</body>
</html>
(~/templates/hello.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
(~/templates/my.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My</title>
</head>
<body>
<h1>My</h1>
</body>
</html>
(pom.xml)
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
...
(스프링 부트에서 자동설정에 의해 생성됨)
기본적인 Username은 user
이며, Password는 애플리케이션 실행 시 랜덤하게 생성됨
의존성을 추가함
(pom.xml)
...
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring-security.version}</version>
<scope>tet</scope>
</dependency>
...
각 메소드 또는 클래스에 @WithMockUser
를 추가하면 정상적으로 동작함
...
@Test
@WithMockUser
public void hello() throws Exception {
mockMvc.perform(get("/hello")
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.