백 엔드에 경량 HTTP 서버 (Jetty)를 배포하는 응용 프로그램이 있습니다.
서블릿은 기본적으로 MySQL 데이터베이스를 업데이트합니다.
나는 스프링을 사용하여 모든 것을 연결했다.lazy-init = "true"입니다. 이유는 무엇입니까? 왜 lazy-init을 true로 설정하지 않고 Swing 앱에서 Spring 빈을 얻을 수 없습니까?
지금까지 확인해보세요.
나는 서버와 상호 작용하는 데 사용할 UI가 있습니다.
UI가 로컬에서 실행되는 경우 현재 로그인 한 사용자 인 JTree
에 표시하려고합니다.
그래서 메인 프레임을 시작할 때 서버를 시작하기로 결정했습니다.
그 외에도 Observer-Observable을 사용하고 로그인을 허용하는 코드를 가지고있는 모든 로그인 사용자를 표시하기 위해 UI의 JTree를 업데이트하려면 Observable
이 필요합니다.
ConnectionListener
SwingUtilities
통해 물론 EDT 스레드 -in를 업데이트 것이다
Jtree
의합니다 (
DefaultMutableTreeNode
루트에 대한 참조를 갖는)을
ArrayBlockingQueue
및 배경 스레드에 저장 들어오는 접속 통지된다.
내 문제는 다음과 같은 : 내가 할 경우
:
public class AdminFrame extends JFrame {
public static ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("myBeans");
public static void main(String[] args){
EventQueue.invokeLater(new Runnable() {
public void run() {
//Show GUI
}
}
}
GUI를 그리는 것이 아니라, 내가 번부터 봄이 시작하는 것이 이해할 수있는 서버가 반환하지 않는 스레드를 시작합니다. 다음과 같이
그래서 나는 백 엔드 스레드에서 봄을 시작합니다
public class ServerThread extends Thread {
@Override
public void run() {
ClassPathXmlApplicationContext ctx = ApplicationCtx.getApplicationCtx();
}
}
및
public class ApplicationCtx {
private static ClassPathXmlApplicationContext ctx;
private ApplicationCtx(){}
public static synchronized ClassPathXmlApplicationContext getApplicationCtx(){
if(ctx == null){
ctx = new ClassPathXmlApplicationContext("myBeans.xml");
}
return ctx;
}
}
GUI는 지금 표시를하고 확인을 보인다하지만 나는 실종 공고.
문제 :
이1) 내가 통지를 등록하면 다음과 같습니다 :
이public class AdminFrame extends JFrame {
public static void main(String[] args) {
ServerThread lightweightServer = new ServerThread();
lightweightServer.start();
Thread.sleep(9000);//Temporary solution to make sure the server is started up before GUI
ConnectHandler connectHandler = (ConnectHandler) ApplicationContext.getApplicationCtx().getBean("connectHandler");
connectHandler.addObserver(new ConnectionListener());
EventQueue.invokeLater(new Runnable() {
public void run() {
//SHOW GUI
}
}
그래픽 사용자 인터페이스가 표시되지 않습니다 새로운 연결에 대한 알림을받을 수 없습니다
. 회선을 삭제하면 :
ConnectHandler connectHandler = (ConnectHandler) ApplicationContext.getApplicationCtx().getBean("connectHandler");
GUI가 나타납니다.
2) 내가 EDT 내부에 등록한 경우, 즉 AdminFrame
의 생성자 안에 GUI가 표시되지 않습니다.
즉,나는 다음 줄을 제거하면
public class AdminFrame extends JFrame {
public static void main(String[] args) {
ServerThread lightweightServer = new ServerThread();
lightweightServer.start();
Thread.sleep(9000);//Temporary solution to make sure the server is started up before
EventQueue.invokeLater(new Runnable() {
public void run() {
AdminFrame frame = new AdminFrame();
//Other code
}
는 다시 GUI가 표시되지만 내가 등록 할 수 없습니다 이런 식으로 알림을받을 :
ConnectHandler connectHandler = (ConnectHandler) ApplicationContext.getApplicationCtx().getBean("connectHandler");
이 스레드 문제가 있어야하지만 난 무엇을 이해할 수 없다 문제.
ConnectHandler
스레드를 반환하지 않는 Spring 응용 프로그램 컨텍스트에 대한 두 번째 호출이 왜 발생합니까?
여기서 내가 뭘 잘못하고 있니?
업데이트 : 나는 부두 서버를 시작하는 빈에 Spring 설정 파일의 속성 lazy-init="true"
를 추가하면 문제가 해결
.
그러나 나는 그것이 그것을 해결하는 이유 또는 무엇이 문제인지 이해할 수 없습니다.
감사
나는이 문제를 안다. 나는 왜'ConnectHandler connectHandler = (ConnectHandler) ApplicationContext.getApplicationCtx(). getBean'이 GUI가 나타나지 않게하는지 이해하지 못한다. EDT.I 빈을 얻고 싶습니다. Spring 컨텍스트가 EDT 외부에서 초기화 된 경우 중요합니까? Spring은 GUI와 관련이 없으며 주로 백엔드의 Jetty 서버를 연결합니다. – Cratylus
@ user384706 일부 코드는 스트림, 연결, unclipped 놓친 스트림, 파일, 연결에 대한 닫히지 않은 및 I/O 수준에서 여전히 활성, 또는 초기화되지 않은 클래스를 호출하는 실수, null, 다음 GUI null, 솔루션 SwingExplorer , 무엇이든 초기화되지 않으면 JProfiler, 많은 행운을 누린다. – mKorbel
'lazy-init' 관찰은 어떨까요?'lazy-init'을 false로 설정하면 코드가 제대로 작동합니다. 게시물 – Cratylus