내 스프링 응용 프로그램에 문제가 발생했습니다.스프링 싱글 톤이 두 번 호출 됨
저는 매우 단순한 봄용 콩을 가지고 있으며, 다른 여러 가지 스프링 콩에 주입됩니다. 내가 찾은 디버깅하는 동안 그들은 두 번 호출되고 있습니다. 생성자 & @PostConstruct 둘 다 두 번 호출됩니다.
내 응용 프로그램에 프런트 엔드 기술이 없습니다. 단순히 백엔드 작업과 관련이 있습니다.
봄 구성
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">
<context:component-scan base-package="com.green.integration" />
<!-- ######################################################## -->
<!-- EXPOSING SPRING BEAN VIA HTTPINVOKER SPRING REMOTING -->
<!-- ######################################################## -->
<bean name="/switch"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="SwitchController" />
<property name="serviceInterface"
value="com.green.ISwitchController" />
</bean>
<!-- Load in application properties reference -->
<bean id="applicationProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:application.properties" />
</bean>
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg value="${mongo.server}" />
<constructor-arg value="${mongo.port}" />
</bean>
<bean id="morphia" class="com.google.code.morphia.Morphia">
</bean>
</beans>
봄 콩 클래스
@Repository
public class TransactionDAO extends BasicDAO<Transaction, ObjectId> {
private Datastore datastore;
@Autowired
public TransactionDAO(Mongo mongo, Morphia morphia) {
super(mongo, morphia, "itransact");
morphia.map(Transaction.class);
// TO USE MONGO WITHOUT SECURITY
this.datastore = morphia.createDatastore(mongo, "itransact");
logger.debug("***** CONNECTED TO MONGODB SUCCESSFULLY *****");
this.datastore.ensureIndexes();
// this.datastore.ensureCaps();
}
}
생성자 "TransactionDAO은"두 번 호출되고있다.
나는Throwable t = new Throwable();
System.out.println(t.getStackTrace()[1].toString());
에 의해 호출 스택 추적을보고 시도 할 때마다 그것은
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
'@ PostConstruct'도 두 번 호출됩니까? 두 번 호출되는 생성자는 쉽게 설명 할 수 있지만 @ PostConstruct는 설명 할 수 없습니다. –
디스패처 서블릿 구성이 있습니까? –
을 통해 다른 컨텍스트의 xml 구성 파일에서 응용 프로그램 컨텍스트 xml을 가져 왔습니까? –