<aside> 1️⃣ 설정정보
</aside>
<?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/maven-v4_0_0.xsd>">
<modelVersion>4.0.0</modelVersion>
<groupId>seoul</groupId>
<artifactId>visitSeoul</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<name>visitSeoul</name>
<url><http://www.egovframe.go.kr></url>
<properties>
<java.version>1.8</java.version>
<spring.maven.artifact.version>3.2.9.RELEASE</spring.maven.artifact.version>
<egovframework.rte.version>3.1.0</egovframework.rte.version>
<tiles.version>3.0.3</tiles.version>
</properties>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
<scope>provided</scope>
</dependency>
<aside> 2️⃣ 생성자 주입 방식 에러사항
</aside>
@Slf4j
@RequiredArgsConstructor
@Service
public class PostSearchServiceImpl implements PostSearchService {
private final PostSearchDAO postSearchDAO;
@Override
public List<PostSearchVO> searchContentList(PostSearchVO postSearchVO) throws Exception {
return postSearchDAO.postSearchList(postSearchVO);
}
}
2023-08-25 08:04:35,664 WARN [org.springframework.beans.factory.support.DisposableBeanAdapter] Invocation of destroy method 'close' failed on bean with name 'sqlSessionTemplate': java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession
2023-08-25 08:04:35,664 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postSearchServiceImpl' defined in file [/Users/jinan/sweetk/sto/project/target/visitSeoul-1.0.0/WEB-INF/classes/humanframework/cms/admin/contentManage/service/impl/PostSearchServiceImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [humanframework.cms.admin.contentManage.service.impl.PostSearchServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: humanframework.cms.admin.contentManage.service.impl.PostSearchServiceImpl.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1037) ~[spring-beans-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:983) ~[spring-beans-3.2.9.RELEASE.jar:3.2.9.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [humanframework.cms.admin.contentManage.service.impl.PostSearchServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: humanframework.cms.admin.contentManage.service.impl.PostSearchServiceImpl.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) ~[spring-beans-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1030) ~[spring-beans-3.2.9.RELEASE.jar:3.2.9.RELEASE]
... 60 more
Caused by: java.lang.NoSuchMethodException: humanframework.cms.admin.contentManage.service.impl.PostSearchServiceImpl.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_372]
at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[?:1.8.0_372]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[spring-beans-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1030) ~[spring-beans-3.2.9.RELEASE.jar:3.2.9.RELEASE]
... 60 more
@Slf4j
@Service
public class PostSearchServiceImpl implements PostSearchService {
private final PostSearchDAO postSearchDAO;
// 생성자 주입
public PostSearchServiceImpl(PostSearchDAO postSearchDAO) {
this.postSearchDAO = postSearchDAO;
}
@Override
public List<PostSearchVO> searchContentList(PostSearchVO postSearchVO) throws Exception {
return postSearchDAO.postSearchList(postSearchVO);
}
}
<aside> 3️⃣ 해결
</aside>
@Slf4j
@Service
public class PostSearchServiceImpl implements PostSearchService {
private final PostSearchDAO postSearchDAO;
// 생성자 주입
@Autowired
public PostSearchServiceImpl(PostSearchDAO postSearchDAO) {
this.postSearchDAO = postSearchDAO;
}
@Override
public List<PostSearchVO> searchContentList(PostSearchVO postSearchVO) throws Exception {
return postSearchDAO.postSearchList(postSearchVO);
}
}
<aside> 4️⃣ 찾아본 내용 feat.ChatGPT
</aside>
@Autowired
애너테이션을 생략할 수 있게 되었다. 그 결과, Lombok의 **@RequiredArgsConstructor
**와 같은 애너테이션을 사용하여 생성자를 자동으로 생성할 때 @Autowired
없이도 의존성 주입이 가능해졌다.