{"id":203960,"date":"2013-11-28T10:12:02","date_gmt":"2013-11-28T06:12:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=203960"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=203960","title":{"rendered":"<span class=\"post_title\">JavaFX \u0438 Spring. \u0412\u043c\u0435\u0441\u0442\u0435 \u0432\u0435\u0441\u0435\u043b\u0435\u0439<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/73f\/397\/692\/73f397692683a00d8433bf7e133477a5.png\"\/><\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0432\u043e\u0435\u043c \u043e\u043f\u044b\u0442\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0449\u0435\u0439 \u043a\u0430\u043a JavaFX \u0438 Spring. \u0418 \u0437\u0430\u043e\u0434\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 Derby \u0438 Maven \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  JavaFX \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0438 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0441\u043a\u0442\u043e\u043f\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Java. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Java SE 7 Update 6, JavaFX \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Oracle Java SE, \u0442.\u0435. \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>  Spring \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0444\u0438\u0448\u0435\u0447\u043a\u0438 \u0432 \u0432\u0438\u0434\u0435 IoC, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u0442.\u0434., \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443.<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>Hello world<\/h4>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0433\u043e FXML.<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"java\">package ru.todolist;  import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage;  public class TodoApplication extends Application {      public static void main(String[] args) {         launch(args);     }      @Override     public void start(Stage primaryStage) throws Exception {         Parent root = FXMLLoader.load(getClass().getResource(&quot;\/fxml\/main.fxml&quot;));         Scene scene = new Scene(root, 300, 275);         primaryStage.setTitle(&quot;Todolist&quot;);         primaryStage.setScene(scene);         primaryStage.show();     } } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 TodoApplication, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u0434\u043b\u044f JavaFX \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FXMLLoader\u2019\u0430 \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 View \u0438\u0437 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432. \u0417\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 View \u0442\u0430\u043a \u0436\u0435 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.<\/p>\n<p>  main.fxml:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;  &lt;?import java.net.*?&gt; &lt;?import javafx.geometry.*?&gt; &lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;?import javafx.scene.text.*?&gt;  &lt;GridPane fx:controller=&quot;ru.todolist.controller.MainController&quot; xmlns:fx=&quot;http:\/\/javafx.com\/fxml&quot; alignment=&quot;center&quot; hgap=&quot;10&quot; vgap=&quot;10&quot; styleClass=&quot;root&quot;&gt;     &lt;Text id=&quot;welcome-text&quot; text=&quot;Hello world!&quot; GridPane.columnIndex=&quot;0&quot; GridPane.rowIndex=&quot;0&quot; GridPane.columnSpan=&quot;2&quot;\/&gt; &lt;\/GridPane&gt; <\/code><\/pre>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0435\u0445\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<h4>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Maven<\/h4>\n<p>  \u0414\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u0433\u0438\u043d \u043e\u0442 <a href=\"http:\/\/zenjava.com\/javafx\/maven\/\">Zen Java<\/a>. \u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0431\u043e\u0440\u043a\u0438 JavaFX \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u043d \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a\u0438 \u0434\u043b\u044f \u043d\u0435\u0433\u043e (MSI, EXE, DMG, RPM) \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 JRE.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 pom.xml:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;     &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;      &lt;groupId&gt;ru.todolist&lt;\/groupId&gt;     &lt;artifactId&gt;application&lt;\/artifactId&gt;     &lt;packaging&gt;jar&lt;\/packaging&gt;     &lt;version&gt;1.0.0&lt;\/version&gt;      &lt;properties&gt;         &lt;log4j.version&gt;1.2.17&lt;\/log4j.version&gt;     &lt;\/properties&gt;       &lt;dependencies&gt;         &lt;dependency&gt;             &lt;groupId&gt;log4j&lt;\/groupId&gt;             &lt;artifactId&gt;log4j&lt;\/artifactId&gt;             &lt;version&gt;${log4j.version}&lt;\/version&gt;         &lt;\/dependency&gt;     &lt;\/dependencies&gt;      &lt;build&gt;         &lt;plugins&gt;             &lt;plugin&gt;                 &lt;groupId&gt;com.zenjava&lt;\/groupId&gt;                 &lt;artifactId&gt;javafx-maven-plugin&lt;\/artifactId&gt;                 &lt;version&gt;2.0&lt;\/version&gt;                 &lt;configuration&gt;                     &lt;mainClass&gt;ru.todolist.TodoApplication&lt;\/mainClass&gt;                 &lt;\/configuration&gt;             &lt;\/plugin&gt;         &lt;\/plugins&gt;     &lt;\/build&gt; &lt;\/project&gt; <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0433\u043b\u0430\u0432\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u043e \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435, \u0442\u0430\u043a \u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:  <\/p>\n<pre><code class=\"cs\">mvn com.zenjava:javafx-maven-plugin:2.0:fix-classpath <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u0442\u043e\u043c \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"http:\/\/zenjava.com\/javafx\/maven\/fix-classpath.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043f\u043b\u0430\u0433\u0438\u043d\u0430.<\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c Derby<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u0447\u0430\u0441\u0442\u044c\u044f \u043d\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0411\u0414 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<p>  \u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c Derby \u0438 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0411\u0414:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;     &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;     &lt;groupId&gt;ru.todolist&lt;\/groupId&gt;     &lt;artifactId&gt;application&lt;\/artifactId&gt;     &lt;packaging&gt;jar&lt;\/packaging&gt;     &lt;version&gt;1.0.0&lt;\/version&gt;      &lt;properties&gt;         &lt;derby.version&gt;10.10.1.1&lt;\/derby.version&gt;\t\t \t\t...     &lt;\/properties&gt;      &lt;dependencies&gt;         &lt;dependency&gt;             &lt;groupId&gt;org.apache.derby&lt;\/groupId&gt;             &lt;artifactId&gt;derbynet&lt;\/artifactId&gt;             &lt;version&gt;${derby.version}&lt;\/version&gt;         &lt;\/dependency&gt;            &lt;dependency&gt;             &lt;groupId&gt;org.apache.derby&lt;\/groupId&gt;             &lt;artifactId&gt;derbyclient&lt;\/artifactId&gt;             &lt;version&gt;${derby.version}&lt;\/version&gt;         &lt;\/dependency&gt;     \t\t...     &lt;\/dependencies&gt;      &lt;build&gt; \t\t...     &lt;\/build&gt; &lt;\/project&gt; <\/code><\/pre>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 TodoApplication \u0442\u0430\u043a, \u0447\u0442\u043e \u0431\u044b \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b \u0411\u0414.   <\/p>\n<pre><code class=\"java\">public class TodoApplication extends Application {     private static Logger LOG = Logger.getLogger(TodoApplication.class);     ...       @Override     public void init() {         try {             DbUtils.startDB();         } catch (Exception e) {             LOG.error(&quot;Problem with start DB&quot;, e);         }     }      @Override     public void stop() {         try {             DbUtils.stopDB();         } catch (Exception e) {             LOG.error(&quot;Problem with stop DB&quot;, e);         }     } } <\/code><\/pre>\n<p>  \u0421\u0430\u043c \u043a\u043b\u0430\u0441\u0441 DbUtils:  <\/p>\n<pre><code class=\"java\">package ru.todolist.utils;  import org.apache.derby.drda.NetworkServerControl; import org.apache.log4j.Logger; import java.net.InetAddress;  public class DbUtils {     private static Logger LOG = Logger.getLogger(DbUtils.class);     private static NetworkServerControl server;      public static void startDB() throws Exception {         LOG.info(&quot;Start DB&quot;);         server = new NetworkServerControl(InetAddress.getByName(&quot;localhost&quot;), 1527);         server.start(null);     }      public static void stopDB() throws Exception {         LOG.info(&quot;Stop DB&quot;);         server.shutdown();     } } <\/code><\/pre>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c Spring<\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f Spring, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0438 Hibernate \u0432 pom.xml:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;     &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;      &lt;groupId&gt;ru.todolist&lt;\/groupId&gt;     &lt;artifactId&gt;application&lt;\/artifactId&gt;     &lt;packaging&gt;jar&lt;\/packaging&gt;     &lt;version&gt;1.0.0&lt;\/version&gt;      &lt;properties&gt; \t\t...         &lt;spring.version&gt;3.2.4.RELEASE&lt;\/spring.version&gt;         &lt;hibernate.version&gt;4.2.6.Final&lt;\/hibernate.version&gt;     &lt;\/properties&gt;       &lt;dependencies&gt;         &lt;dependency&gt;             &lt;groupId&gt;org.hibernate&lt;\/groupId&gt;             &lt;artifactId&gt;hibernate-entitymanager&lt;\/artifactId&gt;             &lt;version&gt;${hibernate.version}&lt;\/version&gt;         &lt;\/dependency&gt;          &lt;dependency&gt;             &lt;groupId&gt;org.springframework&lt;\/groupId&gt;             &lt;artifactId&gt;spring-core&lt;\/artifactId&gt;             &lt;version&gt;${spring.version}&lt;\/version&gt;         &lt;\/dependency&gt;          &lt;dependency&gt;             &lt;groupId&gt;org.springframework&lt;\/groupId&gt;             &lt;artifactId&gt;spring-context&lt;\/artifactId&gt;             &lt;version&gt;${spring.version}&lt;\/version&gt;         &lt;\/dependency&gt;          &lt;dependency&gt;             &lt;groupId&gt;org.springframework&lt;\/groupId&gt;             &lt;artifactId&gt;spring-orm&lt;\/artifactId&gt;             &lt;version&gt;${spring.version}&lt;\/version&gt;         &lt;\/dependency&gt;         ...     &lt;\/dependencies&gt;      &lt;build&gt;         ...     &lt;\/build&gt; &lt;\/project&gt; <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438 View-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043d\u0438\u0445:  <\/p>\n<pre><code class=\"java\">package ru.todolist.utils;  import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.util.Callback; import org.apache.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import ru.todolist.config.AppConfig; import ru.todolist.controller.Controller; import java.io.IOException; import java.io.InputStream;  public class SpringFXMLLoader {      private static Logger LOG = Logger.getLogger(SpringFXMLLoader.class);     private static final ApplicationContext APPLICATION_CONTEXT = new AnnotationConfigApplicationContext(AppConfig.class);      public static Controller load(String url) {         InputStream fxmlStream = null;         try {             fxmlStream = SpringFXMLLoader.class.getResourceAsStream(url);             FXMLLoader loader = new FXMLLoader();             loader.setControllerFactory(new Callback&lt;Class&lt;?&gt;, Object&gt;() {                 @Override                 public Object call(Class&lt;?&gt; aClass) {                     return APPLICATION_CONTEXT.getBean(aClass);                 }             });              Node view = (Node) loader.load(fxmlStream);             Controller controller = loader.getController();             controller.setView(view);              return controller;         } catch (IOException e) {             LOG.error(&quot;Can't load resource&quot;, e);             throw new RuntimeException(e);         } finally {             if (fxmlStream != null) {                 try {                     fxmlStream.close();                 } catch (IOException e) {                     LOG.error(&quot;Can't close stream&quot;, e);                 }             }         }     } } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f Spring\u2019a. \u041c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e URL \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e View, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 AppConfig.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.todolist.config;  import org.hibernate.ejb.HibernatePersistence; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;  import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import java.util.Properties;  @Configuration @ComponentScan(&quot;ru.todolist&quot;) public class AppConfig {      @Bean     public DataSource dataSource() {         DriverManagerDataSource dataSource = new DriverManagerDataSource();         dataSource.setDriverClassName(&quot;org.apache.derby.jdbc.ClientDriver&quot;);         dataSource.setUrl(&quot;jdbc:derby:\/\/localhost:1527\/todo;create=true&quot;); \/\/Create DB if not exist         dataSource.setUsername(&quot;user&quot;);         dataSource.setPassword(&quot;password&quot;);         return dataSource;     }      @Autowired     @Bean     public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(DataSource dataSource) {         LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();         Properties properties = new Properties();         properties.put(&quot;hibernate.dialect&quot;, &quot;org.hibernate.dialect.DerbyDialect&quot;);         properties.put(&quot;hibernate.hbm2ddl.auto&quot;, &quot;create&quot;);         bean.setPersistenceProviderClass(HibernatePersistence.class);         bean.setDataSource(dataSource);         bean.setJpaProperties(properties);         bean.setPackagesToScan(&quot;ru.todolist.model&quot;);         return bean;     }      @Autowired     @Bean     public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory, DataSource dataSource) {         JpaTransactionManager bean = new JpaTransactionManager(entityManagerFactory);         bean.setDataSource(dataSource);         return bean;     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438 \u0432\u0438\u0434:  <\/p>\n<pre><code class=\"java\">package ru.todolist.controller; import javafx.scene.Node;  public interface Controller {     Node getView();     void setView (Node view); } <\/code><\/pre>\n<p>  \u0412\u044b\u043d\u0435\u0441\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 AbstractController.java:  <\/p>\n<pre><code class=\"java\">package ru.todolist.controller; import javafx.scene.Node;  public abstract class AbstractController implements Controller {     private Node view;      public Node getView() {         return view;     }      public void setView (Node view){         this.view = view;     } } <\/code><\/pre>\n<p>  \u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c SprinFXMLLoader \u0432\u0437\u0430\u043c\u0435\u043d \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 TodoApplication:  <\/p>\n<pre><code class=\"java\">public class TodoApplication extends Application { ...     @Override     public void start(Stage primaryStage) throws Exception {         MainController controller = (MainController) SpringFXMLLoader.load(&quot;\/fxml\/main.fxml&quot;);         Scene scene = new Scene((Parent) controller.getView(), 300, 275);         primaryStage.setTitle(&quot;Todolist&quot;);         primaryStage.setScene(scene);         primaryStage.show();     } ... } <\/code><\/pre>\n<h4>\u0418\u0442\u043e\u0433\u0438<\/h4>\n<p>  \u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u044b\u0445 \u0438\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0439. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c JavaFX \u0441 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c \u0441\u0442\u0435\u043a\u043e\u043c \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439 (\u0434\u043b\u044f Java EE) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 Guice.<\/p>\n<h4>\u0420\u0435\u0441\u0443\u0440\u0441\u044b<\/h4>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/zenjava.com\/javafx\/maven\/\">JavaFX Maven Plugin<\/a><\/li>\n<li><a href=\"http:\/\/www.zenjava.com\/series\/building-jee-applications-in-javafx-2-0\/\">\u0426\u0438\u043a\u043b \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 Java EE \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 JavaFX<\/a><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/203960\/\"> http:\/\/habrahabr.ru\/post\/203960\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/73f\/397\/692\/73f397692683a00d8433bf7e133477a5.png\"\/><\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0432\u043e\u0435\u043c \u043e\u043f\u044b\u0442\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0449\u0435\u0439 \u043a\u0430\u043a JavaFX \u0438 Spring. \u0418 \u0437\u0430\u043e\u0434\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 Derby \u0438 Maven \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  JavaFX \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0438 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0441\u043a\u0442\u043e\u043f\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Java. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Java SE 7 Update 6, JavaFX \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Oracle Java SE, \u0442.\u0435. \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>  Spring \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0444\u0438\u0448\u0435\u0447\u043a\u0438 \u0432 \u0432\u0438\u0434\u0435 IoC, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u0442.\u0434., \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-203960","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203960"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203960\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}