JpaRepository cannot be resolved to a type 가 발생합니다 .
896
작성한 질문수 51
JpaRepository cannot be resolved to a type
이러한 에러가 자꾸 떠서 다음으로 넘어가질 못하는데요 ...
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<parent> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.antMart.com</groupId>
<artifactId>springsecurityEducation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springsecurityEducation</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
jap랑 boot 는 다 설정했거던요 ..어디가 문젠지 모르겠어요 maven update계속 해도 마찬가지네요 ..
그리고 서비스파일에
private Collection<? extends GrantedAuthority> authorities() {
return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
}
위에 부분 import가 잘못된건지 아니면 먼가를 빠트렸는지 모르겠네요 다 확인해봐도 정확한 답ㅁ을 못찾겠습니다 .
서비스 파일입니다 .
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class AccountService implements UserDetailsService {
@Autowiredprivate AccountRepositorys accountRepository;
public Account createAccount(String username, String password) {
Account account = new Account();
account.setUsername(username);
account.setPassword(password);
return accountRepository.save(account);
}
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Optional<Account> byUserName = accountRepository.findByUsername(username);
// 없으면 뱉어라
Account account = byUserName.orElseThrow(() -> new UsernameNotFoundException(username));
return new User(account.getUsername(), account.getPassword(), authorities());
}
private Collection<? extends GrantedAuthority> authorities() {
return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
}
}
interface 부분입니다 .
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AccountRepositorys extends JpaRepository<Account, Long> {
Optional findByUsername(String username);
}
runner 부분 입니다 .
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
public class AccountRunner implements ApplicationRunner {
@Autowired
AccountService accountService;
@Overridepublic void run(ApplicationArguments args) throws Exception {
Account account = accountService.createAccount("keesun","1234");
System.out.println(account.getUsername()+""+account.getPassword());
}
}
maven clean과 project clean 여러번 해서 한번 된거같은데 그떄는 Service쪽에서
Description:Field accountRepository in com.antMart.com.AccountService required a bean of type 'com.antMart.com.AccountRepositorys' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.antMart.com.AccountRepositorys' in your configuration.
이러한 에러가 발생했습니다 ..STS 사용중이구요 어디가 잘못된건지 모르겠습니다 ;
답변 1
자동설정 만들기 1부의 Holoman 관련 문의 드립니다.
0
84
1
라이브러리 개발 예제 강의를 찾습니다 !!!
0
225
2
강의 진행되로 똑같이 했는데 jquery가 실행되지 않았는데
0
310
1
HateOas 가 업데이트가 되어서, "Spring HATEOAS" 코드를 아래처럼 하셔야 될겁니다.
0
364
2
springSecurit jwt에 대해서 질문드립니다.
0
343
1
섹션2 자동설정 부분 질문있습니다.
0
249
1
mongo shell 명령어 대체 mongo -> mongosh
0
1012
1
데이터베이스 마이그레이션 강의에서 질문 있습니다
0
707
0
자동 설정 만들기 2부에서 질문 있습니다
0
413
1
의존성 관리 응용 부분에서 질문 있습니다
0
321
0
Intellij 에서 빈 주입할때 계속 빨간줄이 뜨는데 어떻게 고쳐야 할까요
0
1184
1
자동설정으로 다른 프로젝트 빈 사용(번외질문)
0
363
0
CREATE TABLE 예제 따라하다가 'expected "identifier"; SQL statement:' 오류나는 경우
2
2212
2
junit5 관련하여 질문드립니다.
0
307
2
맨 처음 프로젝트 생성 후 Run 시 에러
0
535
2
외부 설정과 관련된 질문입니다.
0
255
1
test와 runner account.setEmail에 동일한 값 입력
0
323
1
컨트롤러 view 호출
0
265
1
JVM 과 arguments 는 뭔가요???
0
1170
1
pom 테그 에러
0
355
1
안녕하십니까 기선님!!!!! webclient와 비동기관련 질문요청드립니다
0
1554
1
webEnvironment 내장 톰캣
0
228
1
application.yml 파일 분리
0
393
1
안녕하세요 기선님 서블릿 어플리케이션 구조에 대해 질문드립니다
0
281
1





