tag:blogger.com,1999:blog-40980437771738518522023-12-07T12:56:10.623+02:00Programming notesabout java, spring, android, app performance and architectureSergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.comBlogger110125tag:blogger.com,1999:blog-4098043777173851852.post-9422598443166298312022-12-05T12:05:00.001+02:002023-01-29T12:14:46.167+02:00Migrating a project from Java 11 to Java 17<p>Java 17 is new LTS version and it make sense to migrate existing projects to the new version. I will describe my specific case</p>
<a name='more'></a>
<p><br /></p><p>1) So first I updated maven pom.xml and put there - <java.version>17</java.version></p><p>2) Next I updated docker image - to this one - openjdk:17</p><p>3) In dependencies I have spring boot so updated it to version 2.6.8 </p><p>4) There were some difficulties with Ignite Cache, we should use previous version that uses some features from previous jdk that why I added this vm options to open access to closed packets:
</p><pre class="brush: xml;"><plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-surefire-plugin</artifactid>
<version>3.0.0-M7</version>
<configuration>
<argline>--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED
--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED
--add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED
--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.time=ALL-UNNAMED
</argline>
</configuration>
</plugin>
</pre>
<p></p>5) We need to add the same options in java opts when we starting our application, we use docker how i said so i created JAVA_OPTS vars with props above, and added to docker run
<pre class="brush: xml;">ENTRYPOINT java $JAVA_OPTS -jar super-project.jar
</pre>
6) Next there were some issues with swagger that why I updated to springdoc-openapi-ui 1.6.11<div><br /></div><div>7) I've spent a lot of time to resolve issue with Jaeger tracing, it was disabled locally and everything was ok but when we start our app on server we have exceptions. So we decided to move from jaeger to spring-cloud-starter-sleuth - <span style="background-color: white; color: #080808; font-family: "JetBrains Mono", monospace;">2021.0.2</span> </div><div><br /></div><div>In general, these are the most notable bugs I encountered during the migration to Java 17 which I found useful to mention. So it is not scary at all)</div>Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-33186415260203144842020-09-11T09:37:00.000+03:002020-09-11T09:37:00.177+03:00Generate settings-security.xml file for maven password encryption<p> <code style="border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">mvn --encrypt-master-password</code><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> </span><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;">does not create a file</span><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> </span><code style="border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">security-settings.xml</code><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;">. </span></p><ol style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1.4667em 30px; padding: 0px; vertical-align: baseline;"><li style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.7em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">Use the command <code style="background-color: var(--black-075); border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">mvn --encrypt-master-password</code> to generate a master password. Remember this password.</li><li style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">Create a new file <code style="background-color: var(--black-075); border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">security-settings.xml</code> in <code style="background-color: var(--black-075); border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">${user.home}/.m2/</code>. For example, on Mac OS X or Ubuntu as <code style="background-color: var(--black-075); border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">~/.m2/settings-security.xml</code>.</li></ol><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;">Write into this file:</p><pre class="lang-xml prettyprint prettyprinted" style="border-radius: 5px; border: 0px; box-sizing: inherit; color: var(--highlight-color); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.30769; margin-bottom: 1.6em; margin-top: 0px; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px; vertical-align: baseline; width: auto;"><code style="border-radius: 0px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><settingsSecurity></span><span class="pln" style="border: 0px; box-sizing: inherit; color: var(--black-750); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><master></span><span class="pln" style="border: 0px; box-sizing: inherit; color: var(--black-750); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">OUTPUT OF THE COMMAND: mvn --encrypt-master-password</span><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></master></span><span class="pln" style="border: 0px; box-sizing: inherit; color: var(--black-750); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></settingsSecurity></span></code></pre><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;">e.g.:</p><pre class="lang-xml prettyprint prettyprinted" style="border-radius: 5px; border: 0px; box-sizing: inherit; color: var(--highlight-color); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.30769; margin-bottom: 1.6em; margin-top: 0px; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px; vertical-align: baseline; width: auto;"><code style="border-radius: 0px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><settingsSecurity></span><span class="pln" style="border: 0px; box-sizing: inherit; color: var(--black-750); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><master></span><span class="pln" style="border: 0px; box-sizing: inherit; color: var(--black-750); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</span><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></master></span><span class="pln" style="border: 0px; box-sizing: inherit; color: var(--black-750); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: var(--red-800); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></settingsSecurity></span></code></pre><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;">After that the maven encrypt command works on the command line:</p><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;"><code style="background-color: var(--black-075); border-radius: 3px; border: 0px; box-sizing: inherit; color: var(--black-800); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 2px 4px; vertical-align: baseline; white-space: pre-wrap;">mvn --encrypt-password</code></p><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;">As mentioned by khmarbaise, more detailed information can be found here: <a href="https://maven.apache.org/guides/mini/guide-encryption.html" rel="nofollow noreferrer" style="border: 0px; box-sizing: inherit; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">https://maven.apache.org/guides/mini/guide-encryption.html</a></p><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;"><br /></p><p style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 1.4667em; padding: 0px; vertical-align: baseline;"><a href="https://stackoverflow.com/questions/51503336/generate-settings-security-xml-file-for-maven-password-encryption" target="_blank">source</a> </p>Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-77656433296067083342020-06-01T22:48:00.002+03:002020-06-01T23:14:04.564+03:00Intellij Idea can't resolve generated class<div dir="ltr" style="text-align: left;" trbidi="on">
It was really annoying issue, we had some maven plugin that generates classes from some schema, and for some reason Intellij Idea cant resolve this class. It just marks it with red. The reason was too big file size i've increased it like this:<br />
<br />
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"><span style="color: #8c8c8c; font-style: italic;"># Maximum file size (kilobytes) IDE should provide code assistance for.</span></pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"><span style="color: #083080;">idea.max.intellisense.filesize</span>=<span style="color: #067d17;">6000</span><span style="color: #067d17;">
</span><span style="color: #8c8c8c; font-style: italic;">
</span></pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"><span style="color: #8c8c8c; font-style: italic;"># Maximum file size (kilobytes) IDE is able to open.</span></pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"><span style="color: #083080;">idea.max.content.load.filesize</span>=<span style="color: #067d17;">6000</span></pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"><span style="color: #067d17;">
</span></pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"><span style="color: #067d17;">in </span>Help > Edit Custom Properties</pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;"></pre>
<pre style="background-color: white; color: #080808; font-family: 'JetBrains Mono'; font-size: 9,8pt;">and then File > Restart & invalidate</pre>
</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-29333765383665321872020-04-28T14:36:00.001+03:002020-04-28T15:33:15.906+03:00End-to-end tests with Spring and Test Containers<div dir="ltr" style="text-align: left;" trbidi="on">
I've heard previously about <a href="https://www.testcontainers.org/">test-containers</a> but didn't have chance to read about it. Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.<br />
<br />
So basically it simplify you process of creating and maintaining end-to-end tests. You no need external containers you simple can run in on jenkins during your usual testing life cycle.<br />
<br />
Two articles illustrate this approach with <a href="https://medium.com/@gustavo.ponce.ch/spring-boot-crud-service-testcontainers-docker-selenium-cf0739bcc25"> Selenium</a> and one more with <a href="https://dzone.com/articles/advanced-functional-testing-in-spring-boot-by-usin">WireMock</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-71283744884532221292020-04-26T17:45:00.002+03:002020-04-26T18:48:54.619+03:00Micrometer - SLF4J but for metrics<div dir="ltr" style="text-align: left;" trbidi="on">
Nice tool to try, <a href="https://github.com/micrometer-metrics/micrometer-docs">Micrometer</a> is - facade over the instrumentation clients for a number of popular monitoring systems. Currently, it supports the following monitoring systems: Atlas, Datadog, Graphite, Ganglia, Influx, JMX and Prometheus. More in <a href="https://www.baeldung.com/micrometer">tutorial</a><br />
<br />
Syntaxis is simple and straightforward:<br />
<br />
<code class="java spaces" style="background-attachment: initial !important; background-clip: initial !important; background-image: initial !important; background-origin: initial !important; background-position: 0px 0px !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: #333333; float: none !important; font-family: "source code pro", consolas, "bitstream vera sans mono", "courier new", Courier, monospace !important; font-size: 14px; height: auto !important; left: auto !important; line-height: 1.43 !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"> </code><code class="java plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: initial !important; background-origin: initial !important; background-position: 0px 0px !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: "source code pro", consolas, "bitstream vera sans mono", "courier new", Courier, monospace !important; font-size: 14px; height: auto !important; left: auto !important; line-height: 1.43 !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">Metrics.counter(</code><code class="java string" style="background-attachment: initial !important; background-clip: initial !important; background-image: initial !important; background-origin: initial !important; background-position: 0px 0px !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(99, 177, 117) !important; float: none !important; font-family: "source code pro", consolas, "bitstream vera sans mono", "courier new", Courier, monospace !important; font-size: 14px; font-weight: 600 !important; height: auto !important; left: auto !important; line-height: 1.43 !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">"objects.instance"</code><code class="java plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: initial !important; background-origin: initial !important; background-position: 0px 0px !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: "source code pro", consolas, "bitstream vera sans mono", "courier new", Courier, monospace !important; font-size: 14px; height: auto !important; left: auto !important; line-height: 1.43 !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">).increment();</code><br />
<br /></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-42766302277984296902020-03-29T16:43:00.001+03:002020-04-27T15:05:14.216+03:00Spring Data and MongoDb aggregation examples<div dir="ltr" style="text-align: left;" trbidi="on">
I've faced recently with some not trivial mongo aggregation queries and found there are not so many examples available, so main source is official docs <a href="https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#introduction">https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#introduction</a><br />
<br />
also was useful tests of the Spring Framework:<br />
<br />
<a href="https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationTests.java">https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationTests.java</a><br />
<br />
<a href="https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java">https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java</a><br />
<br />
use to profile query<br />
db.events.explain("executionStats").aggregate("query") </div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-37825663602275288382019-10-27T22:03:00.000+02:002020-04-26T18:49:09.941+03:00Useful Java tools to try<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://www.youtube.com/watch?v=wm2JNlaJJ5k">java mission control</a> - to monitor jvm<br />
<br />
<a href="https://github.com/Kotlin/kotlinx-lincheck">lincheck </a>- <span style="background-color: white; color: #24292e; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji"; font-size: 16px;">testing concurrent data structures</span><br />
<span style="background-color: white; color: #24292e; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji"; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #24292e; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji"; font-size: 16px;"><a href="https://openjdk.java.net/projects/code-tools/jmh/">jmh </a>- it is tool for microbenchmarking your code</span><br />
<span style="background-color: white; color: #24292e; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji"; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #24292e;"><a href="https://debezium.io/">debezium</a> - tool to capture database changes (mongo, oracle...)</span></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-63848756509751595692019-10-27T21:54:00.000+02:002019-10-31T20:56:48.841+02:00Spring Cloud Contract<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://spring.io/projects/spring-cloud-contract">Cool tool</a> to test interaction between you apps without running all of them. Need just describe contract of you service and inject in via wiremock were it is needed. Here is a <a href="https://www.baeldung.com/spring-cloud-contract">tutorial</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-20678349552550198672019-10-27T21:43:00.001+02:002019-10-27T21:43:33.270+02:00Spring reactive<div dir="ltr" style="text-align: left;" trbidi="on">
Spring introduced reactive support with <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux">WebFlux</a> it implements basic Reactive concepts. It works with Netty, non blocking server.<br />
<br />
Also Spring added support of the <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#rsocket">RSocket </a>protocol it is not based on HTTP and provides nice features as back-pressure. You can establish direct connection from the web-browser to rsocket server. Spring provides API to implement listeners, smth similar like rest controllers.</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-1790476178098965012019-03-10T17:40:00.000+02:002019-03-11T11:08:43.510+02:00Spring Boot 2 and custom JsonSerializer<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I was migrating recently to the new Spring Boot version 2. And most annoying thing was that PageImpl (component used for pagination) changed format. Also I had some issues with Mockito 2, but all of them could be solved <a href="https://asolntsev.github.io/en/2016/10/11/mockito-2.1/">read here</a>.<br />
<br />
<a name='more'></a><br />
Well I found <a href="https://wimdeblauwe.wordpress.com/2018/06/10/pageimpl-json-serialization-with-spring-boot-2/">this article</a> and it all looked easy despite the fact that Spring did not want to use my JsonSerializer. Here how it looks:<br />
<br />
<pre class="brush: java;">import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Sort;
import java.io.IOException;
@JsonComponent
public class PageImplJacksonSerializer extends JsonSerializer {
@Override
public void serialize(PageImpl page, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeObjectField("content", page.getContent());
jsonGenerator.writeBooleanField("first", page.isFirst());
jsonGenerator.writeBooleanField("last", page.isLast());
jsonGenerator.writeNumberField("totalPages", page.getTotalPages());
jsonGenerator.writeNumberField("totalElements", page.getTotalElements());
jsonGenerator.writeNumberField("numberOfElements", page.getNumberOfElements());
jsonGenerator.writeNumberField("size", page.getSize());
jsonGenerator.writeNumberField("number", page.getNumber());
Sort sort = page.getSort();
jsonGenerator.writeArrayFieldStart("sort");
for (Sort.Order order : sort) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("property", order.getProperty());
jsonGenerator.writeStringField("direction", order.getDirection().name());
jsonGenerator.writeBooleanField("ignoreCase", order.isIgnoreCase());
jsonGenerator.writeStringField("nullHandling", order.getNullHandling().name());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
}
</pre>
<div>
</div>
Next I read Spring docs of how can I customize Serializer <a href="https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring">here </a>and <a href="https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-customize-the-jackson-objectmapper">here</a>
They suggested to create jacksonBuilder with your specific module or register JsonComponentModule that will find your serializer that will be used by spring during mapper creation. Unfortunately none of this worked for me:
<br />
<br />
<br />
<pre class="brush: java;"> @Bean
public Module jsonComponentModule() {
return new JsonComponentModule();
}</pre>
<br />
And this also didn't work:
<br />
<br />
<pre class="brush: java;"> @Bean
@Primary
public Jackson2ObjectMapperBuilder jacksonBuilder() {
JsonComponentModule module = new JsonComponentModule();
module.addSerializer(PageImpl.class, new PageImplJacksonSerializer());
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.modulesToInstall(module);
return builder;
}
</pre>
<div>
</div>
I continued with my last idea, suggested by docs is configuring HttpMessageConverter.
And here I figured out that my config extends WebMvcConfigurationSupport to enable MVC and
after debugging spring context creation. I found that Spring registers default converters with method
addDefaultHttpMessageConverters and following line of code and for some reason it does not register serializer here:
<br />
<br />
<pre class="brush: java;">messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));</pre>
<br /></div>
<br />
So here is working solution for me, with configuring default converter created by Spring:
<br />
<br />
<pre class="brush: java;">@Override
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter converter = (MappingJackson2HttpMessageConverter)
converters.stream()
.filter(c -> c instanceof MappingJackson2HttpMessageConverter)
.findFirst().get();
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
JsonComponentModule module = new JsonComponentModule();
module.addSerializer(PageImpl.class, new PageImplJacksonSerializer());
ObjectMapper objectMapper = builder.modules(module).build();
converter.setObjectMapper(objectMapper);
}</pre>
</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com4tag:blogger.com,1999:blog-4098043777173851852.post-19053274533405371082018-08-13T22:59:00.006+03:002018-08-13T22:59:58.968+03:00Spring Boot articles to read <div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://www.e4developer.com/2018/08/06/spring-boot-best-practices/">https://www.e4developer.com/2018/08/06/spring-boot-best-practices/</a><br />
<br />
<a href="https://www.e4developer.com/2018/03/30/introduction-to-concurrency-in-spring-boot/">https://www.e4developer.com/2018/03/30/introduction-to-concurrency-in-spring-boot/</a><br />
<br />
<a href="https://www.e4developer.com/2018/04/28/springs-webflux-reactor-parallelism-and-backpressure/">https://www.e4developer.com/2018/04/28/springs-webflux-reactor-parallelism-and-backpressure/</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-89739777194024377162018-06-26T15:18:00.002+03:002018-06-26T15:18:28.794+03:00JVM benchmark example<div dir="ltr" style="text-align: left;" trbidi="on">
A JVM benchmark example from real project (QuickFIX/J is library that implements finacial FIX protocol) <a href="https://github.com/quickfix-j/quickfixj/wiki/JMH-benchmark-for-%2339-and-%2342">https://github.com/quickfix-j/quickfixj/wiki/JMH-benchmark-for-%2339-and-%2342</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-78600870836752970262018-03-24T18:49:00.000+02:002018-03-24T18:49:04.968+02:00Log4j not printing the stacktrace for exception<div dir="ltr" style="text-align: left;" trbidi="on">
I've noticed interesting behavior in the server logs on jdk 8. There was an exception without stack trace. After small research I have found that hotspot may apply some optimization to exceptions that are thrown too frequent, it simply trim stack trace) So I scrolled to the first occurrences of the exception and found my stack trace. Here is oracle docs describing it:<br />
<br />
<a href="http://www.oracle.com/technetwork/java/javase/relnotes-139183.html">http://www.oracle.com/technetwork/java/javase/relnotes-139183.html</a><br />
<br />
and you can disable it with <span style="background-color: white; color: #666666; font-family: courier, "courier new", monaco; font-size: 12px;">-XX:-OmitStackTraceInFastThrow</span></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com1tag:blogger.com,1999:blog-4098043777173851852.post-90989130232191196962017-09-17T01:03:00.003+03:002018-08-14T00:18:26.400+03:00Spring 5 and HSQLDB sample app<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="font-family: inherit;">Recently I have played a bit with Spring 5 and embedded database HSQLDB. It is very not usual for me to create Spring app even without single xml. Also I used cool </span>library<span style="font-family: inherit;"> called </span><a href="https://projectlombok.org/">Lombok</a> it provides auto getter/setter generation.</div>
<div style="text-align: left;">
<span style="font-family: inherit;"><span style="background-color: white; color: #24292e; font-size: 16px;"><br /></span></span></div>
<div style="text-align: left;">
<span style="background-color: white;"><span style="color: #24292e;"><span style="font-family: inherit;">What was interesting for me that spring-boot auto </span>configure<span style="font-family: inherit;"> for you </span></span><span style="color: #24292e;">following</span><span style="color: #24292e; font-family: inherit;"> features: mvc, transactions, json serialization, jpa, tests. It has even embedded tomcat)</span></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><span style="background-color: white; color: #24292e; font-size: 16px;"><br /></span></span></div>
<div style="text-align: left;">
Here is my github <a href="https://github.com/safonovserg/monitoringapp" style="font-family: inherit; font-size: 16px;">repository</a></div>
</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-51147465953544479302017-07-02T16:14:00.000+03:002017-07-02T16:16:11.435+03:00Java 8 Run-Time Evaluation of Lambda Expressions<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.4">http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.4</a><br />
<br />
<a href="https://www.infoq.com/articles/Java-8-Lambdas-A-Peek-Under-the-Hood">Java 8 Lambdas - A Peek Under the Hood</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-38674906355139262932017-06-25T22:33:00.002+03:002019-01-20T20:54:03.916+02:00Machine learning <div dir="ltr" style="text-align: left;" trbidi="on">
Choosing the right estimator<br />
<a href="http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html">http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html</a><br />
<a href="https://www.dropbox.com/s/nz2d6uquwn59fz6/ml_map.png">https://www.dropbox.com/s/nz2d6uquwn59fz6/ml_map.png</a><br />
<br />
later i will add here more machine learning stuff<br />
<br />
<a href="https://habr.com/post/350984/">Первые шаги в машинном обучении</a><br />
<br />
<a href="https://medium.com/@ageitgey/machine-learning-is-fun-80ea3ec3c471">Machine Learning is Fun! The world’s easiest introduction to Machine Learning</a><br />
<br />
<a href="https://oracle.github.io/graphpipe/#/">https://oracle.github.io/graphpipe/#/</a><br />
<br />
<a href="https://github.com/neomatrix369/awesome-ai-ml-dl">https://github.com/neomatrix369/awesome-ai-ml-dl</a><br />
<br /></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-82318731350106194292017-06-15T00:18:00.000+03:002017-06-17T01:16:10.105+03:00A different object with the same identifier value was already associated with the session<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;">Hibernate Error: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session</span><br />
<span style="font-family: inherit;"><b><span style="font-family: inherit;"><br /></span></b>
<b><span style="font-family: inherit;">What is the reason of such exception?</span></b></span><br />
<span style="font-family: inherit;"><span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Session already contains object that you are trying to put there one more time with such identifier (for example with update). It also could be <span style="background-color: white; color: #242729; font-size: 15px;">many-to-one</span><span style="background-color: white; color: #242729; font-size: 15px;"> or one-to-many </span><span style="color: #242729;"><span style="font-size: 15px;">relationship object or cascading operation.</span></span></span></span><br />
<span style="font-family: inherit;"><span style="color: #242729; font-family: inherit;"><span style="font-size: 15px;"><br /></span></span>
<span style="color: #242729; font-family: inherit;"><span style="font-size: 15px;"><b>How to deal with it?</b></span></span></span><br />
<ul style="text-align: left;">
<li><span style="font-family: inherit;">probably you already called update() for this object, and trying do this 2nd time</span></li>
</ul>
<ul style="text-align: left;">
<li><span style="font-family: inherit;">another possible reason you making copy of the object that is already associated with session (has assigned id and was loaded recently) and trying<span style="color: #242729; font-size: 15px;"> to update it</span></span></li>
</ul>
<ul style="text-align: left;">
<li><span style="font-family: inherit;">try session.<a href="https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Session.html#merge(java.lang.Object)" style="font-size: 15px;">merge</a><span style="color: #242729; font-size: 15px;">() - it will copy the state of the given object into the persistent object with the same identifier.</span></span></li>
</ul>
<ul style="text-align: left;">
<li><span style="font-family: inherit;">try session.<a href="https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Session.html#evict(java.lang.Object)">evict</a>(object) - r<span style="color: #242729;"><span style="font-size: 15px;">emove this instance from the session cache.</span></span></span></li>
</ul>
</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com3tag:blogger.com,1999:blog-4098043777173851852.post-19399237248337036342017-06-11T21:59:00.000+03:002020-04-26T18:46:18.991+03:00Domain Driven Design in Java<div dir="ltr" style="text-align: left;" trbidi="on">
I think most enterprise java world is suffering from <a href="https://martinfowler.com/bliki/AnemicDomainModel.html">Anemic Domain Model</a>. One of the ways that can help you is DDD. I've started researching DDD area, and I've found couple of good books and sources for them:<br />
<br />
<a href="https://www.safaribooksonline.com/library/view/implementing-domain-driven-design/9780133039900/">Implementing Domain-Driven Design by Vaughn Vernon</a> (I think it is good to start book)<br />
<br />
and source code is here : <a href="https://github.com/VaughnVernon/IDDD_Samples">https://github.com/VaughnVernon/IDDD_Samples</a><br />
<br />
And one more book called <a href="https://www.safaribooksonline.com/library/view/domain-driven-design-tackling/0321125215/">Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans </a><br />
<br />
and source code is here: <a href="https://github.com/citerus/dddsample-core">https://github.com/citerus/dddsample-core</a><br />
<br />
more code samples <a href="https://github.com/ddd-by-examples/library">https://github.com/ddd-by-examples/library</a><br />
<a href="https://github.com/mploed/ddd-with-spring">https://github.com/mploed/ddd-with-spring</a><br />
<br /></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-61069665635065380512017-03-13T22:52:00.001+02:002017-03-13T23:15:18.393+02:00Free Java hosting options and Heroku tomcat deployment <div dir="ltr" style="text-align: left;" trbidi="on">
I wanted to write some java app that would communicate with 3rd party API. The main problem there was that this API requires https connection. So I needed free java hosting to test my concept.<br />
<br />
I will describe my short research about free java hosting proposals. And will describe shortly <a href="https://dashboard.heroku.com/">Heroku </a>quick start.<br />
<a name='more'></a><br />
<b>My main options were:</b><br />
<ul style="text-align: left;">
<li>Amazon AWS - it is free for one year. It has EC2 - it is linux virtual machine solution and Elastic Beanstalk - it is like a pass with command line to interact. The main disadvanges for me that it doesn't have free SSL.</li>
</ul>
<ul style="text-align: left;">
<li>Digital Ocean - it is not free but gives you Linux virtual machine.</li>
</ul>
<ul style="text-align: left;">
<li>Cloudflare - PaaS, it has SSL and it is free. Unfortunately didn't have chance to try it.</li>
</ul>
<ul style="text-align: left;">
<li>Openshift - it is PaaS, i tried it couple of years ago and it was too complicated for simple apps.</li>
</ul>
<ul style="text-align: left;">
<li>Heroku - it is PaaS that has SSL support. What is most optimal option for me. Main disadvantage could be that it is idling your app each 30 minutes if it is inactive, but it was ok for me.</li>
</ul>
<br />
<b>So here is few steps that need to be done to deploy you java app on Heroku tomcat server:</b><br />
<br />
1) Need to install Heroku CLI it includes Git<br />
<br />
2) need to create maven project with Procfile file in the root, it should contain:<br />
<i>web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war</i><br />
<br />
3) Commit your chages to Git<br />
<div>
<div>
<i>git init</i></div>
<div>
<i>git add .</i></div>
<div>
<i>git commit -m "Ready to deploy"</i></div>
</div>
<div>
<br /></div>
<div>
4) Crete the app and & remote Git repo (of course login first with heroku login)</div>
<div>
<i>heroku create</i></div>
<div>
<br /></div>
<div>
5) Deploy your code</div>
<div>
<i>git push heroku master</i></div>
<div>
<br /></div>
<div>
6) Open your app url</div>
<div>
<i>heroku open</i></div>
<div>
<br /></div>
<div>
Voila)</div>
<div>
<br /></div>
<div>
<b>Also useful commands:</b></div>
<div>
To show logs</div>
<div>
<i>heroku logs --tail</i></div>
<div>
<br /></div>
<div>
To enable scalling</div>
<div>
<div>
<i>heroku ps:scale web=1</i></div>
</div>
<div>
<br /></div>
<div>
To open bash console</div>
<div>
<i>heroku run bash</i></div>
<div>
<br /></div>
<div>
To see addons, add databse</div>
<div>
<i>heroku addons</i></div>
<div>
<br /></div>
<div>
To see config vars</div>
<div>
<i>heroku config</i></div>
<div>
<br /></div>
<div>
<b>Resources:</b></div>
<div>
<a href="https://devcenter.heroku.com/articles/getting-started-with-java#introduction">Getting Started on Heroku with Java</a></div>
<div>
<a href="https://devcenter.heroku.com/articles/java-webapp-runner#deploy-your-application-to-heroku">Deploying Tomcat-based Java Web Applications with Webapp Runner</a></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com1tag:blogger.com,1999:blog-4098043777173851852.post-490536732894708912017-03-04T11:24:00.000+02:002017-03-04T11:24:10.168+02:00The top of most mentioned books on stackoverflow.com<div dir="ltr" style="text-align: left;" trbidi="on">
Top 5:<br />
#1 Working Effectively with Legacy Code<br />
Michael C. Feathers<br />
#2 Design Patterns<br />
Ralph Johnson, Erich Gamma, John Vlissides, Richard Helm<br />
#3 Clean Code<br />
Robert C. Martin<br />
#4 Java concurrency in practice<br />
Brian Goetz, Tim Peierls<br />
#5 Domain-driven Design<br />
Eric Evans<br />
<br />
See more here <a href="http://www.dev-books.com/">http://www.dev-books.com/</a><br />
<br /></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-75033073678948201532017-02-22T21:31:00.001+02:002017-02-22T21:31:44.894+02:00Spring Boot: A Quick Start<div dir="ltr" style="text-align: left;" trbidi="on">
Hmm spring configuration is getting better)<br />
<a href="https://dzone.com/articles/spring-boot-a-quick-start">https://dzone.com/articles/spring-boot-a-quick-start</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-34870784589361817702017-02-16T00:49:00.000+02:002017-02-22T21:25:52.676+02:00Scrum in few words<div dir="ltr" style="text-align: left;" trbidi="on">
Note about scrum. It is mostly based on Scum Guide but in much shorter way and with some examples from my experience.
<br />
<a name='more'></a><br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Scrum <i></i></b>is a framework for developing and sustaining complex products<br />
<h2 style="text-align: left;">
<b><span style="font-size: x-large;">Roles</span></b></h2>
<i><b>The Product Owner</b></i> - is the person responsible for managing the Product Backlog (describing items, ordering and prioritization ). Also Product owner may delegate his responsibilities to the Dev Team.<br />
However, the
Product Owner remains accountable, and you should consult with him.<br />
<br />
<b><i>The Development Team</i> </b> - decide how to turn Product Backlog into Increments of potentially releasable functionality. Are cross-functional, with all of the skills to create
a product Increment;<br />
<i>Usually having 3-9 members.</i><br />
<i><br /></i>
<i><b>The Scrum Master</b> </i>-is responsible for ensuring Scrum is understood and enacted.<i> </i><br />
<br />
Service to the Product Owner (help in Product Backlog management, helping the Scrum Team understand product backlog items, Facilitating Scrum events)<br />
<br />
Service to the Development Team (Coaching, Helping the Development Team to create product, Facilitating Scrum events, Removing impediments)<br />
<h2 style="text-align: left;">
<b><span style="font-size: x-large;">Scrum Events</span></b></h2>
The heart of Scrum is a <b><i>Sprint</i></b>, a time-box of <i>one month or less</i> during which a “Done”, usable,
and potentially releasable product Increment is created. Sprints best have consistent duration
throughout a development effort. A new Sprint starts immediately after the conclusion of the
previous Sprint.<br />
<br />
Sprints contain and consist of the Sprint Planning, Daily Scrums, the development work, the
Sprint Review, and the Sprint Retrospective.<br />
<br />
<b>Sprint Planning </b><br />
Sprint Planning answers the following:<br />
<ul style="text-align: left;">
<li>What can be delivered in the Increment resulting from the upcoming Sprint? </li>
<li>How will the work needed to deliver the Increment be achieved? </li>
</ul>
<div>
The input to this meeting is the Product Backlog, the latest product Increment, projected
capacity of the Development Team during the Sprint, and past performance of the Development
Team. The number of items selected from the Product Backlog for the Sprint is solely up to the
Development Team. Only the Development Team can assess what it can accomplish over the
upcoming Sprint.</div>
<br />
The Development Team usually starts by designing the system and the work needed to convert
the Product Backlog into a working product Increment.<br />
<br />
The Product Owner can help to clarify the selected Product Backlog items and make trade-offs.
If the Development Team determines it has too much or too little work, it may renegotiate the
selected Product Backlog items with the Product Owner.<br />
<br />
<i>For example each member says his capacity. Scrum master displays all jiras with some release version. All team estimates jiras. You could also use excell to group planned tasks.</i><br />
<i><br /></i>
<i>Frequent approach is sending </i><i>email with </i><i>sprint backlogs items after planning to Product Owner (if he can't participate)</i><br />
<br />
<b>Sprint Goal </b><br />
The Sprint Goal is an objective set for the Sprint that can be met through the implementation of
Product Backlog. It provides guidance to the Development Team on why it is building the
Increment.<br />
<br />
<i>Try to make it clear, you could use SMART approach </i><br />
<br />
<b>Daily Scrum</b><br />
The Daily Scrum is a 15-minute time-boxed event for the Development Team to synchronize
activities and create a plan for the next 24 hours. This is done by inspecting the work since the
last Daily Scrum and forecasting the work that could be done before the next one.<br />
<br />
the Development Team members explain:<br />
<ul style="text-align: left;">
<li>What did I do yesterday that helped the Development Team meet the Sprint Goal? </li>
<li>What will I do today to help the Development Team meet the Sprint Goal? </li>
<li>Do I see any impediment that prevents me or the Development Team from meeting the
Sprint Goal? </li>
</ul>
<i>Very useful is tracking progress of each individual task (maybe visually), tracking time (ex member A done 2h from 15h ), use color markers for each task (red/green/blue approach depending on item, status).</i><br />
<i><br /></i>
<i> It could be on scrum board with three main parts todo/ in progress/ done.</i><br />
<br />
<b>Sprint Review</b><br />
A Sprint Review is held at the end of the Sprint to inspect the Increment and adapt the Product
Backlog if needed.During the Sprint Review, the Scrum Team and stakeholders, product owner collaborate
about what was done in the Sprint.The entire group collaborates on what to do next.<br />
<br />
The result of the Sprint Review is a revised Product Backlog<br />
<div>
<br /></div>
<i>For example demo of new features is good thing here. </i><br />
<br />
<b>Sprint Retrospective</b><br />
The Sprint Retrospective is an opportunity for the Scrum Team to inspect itself and create a plan
for improvements to be enacted during the next Sprint. Inspect how the last Sprint went with regards to people, relationships, process,and tools.<br />
<br />
<i>Good approach here to write on board pluses and minuses and possible todo plan to implement in new sprint.</i><br />
<h2 style="text-align: left;">
<b><span style="font-size: x-large;">Scrum Artifacts </span></b></h2>
<b>Product Backlog -</b> is an ordered list of everything that might be needed in the product.<br />
<br />
<i>Good technique sometimes is to refine some big or complex product backlog items for the next sprint, to be able to estimate them well on the planning</i><br />
<br />
<b>Sprint Backlog</b> - is the set of Product Backlog items selected for the Sprint, plus a plan for
delivering the product Increment and realizing the Sprint Goal. It is only forecast.<br />
<br />
<i>Good technique is to add label in jira with sprint number</i><br />
<br />
<b>Definition of “Done” - </b>when a Product Backlog item or an Increment is described as “Done”, everyone must
understand what “Done” means.<br />
<br />
<i>For example developer committed change and closed an jira, QA passed jira, Reporter closed it. </i><br />
<i><br /></i>
<i>Good technique is to have it printed somewhere to be visible for all team.</i><br />
<i><br /></i>
<b>References</b><br />
<a href="http://www.scrumguides.org/download.html">Download the official Scrum Guide</a><br />
<a href="https://dzone.com/articles/stuff-every-agile-development-team-needs-to-know-a">Stuff Every Agile Development Team Needs to Know: A Primer</a><br />
<br /></div>
</div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com2tag:blogger.com,1999:blog-4098043777173851852.post-65763101950098063202017-02-08T23:49:00.002+02:002017-04-07T20:06:09.105+03:00Spring Transactions management tips<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In this article I will describe ways of managing transactions in Spring. And will share some useful notes based on my experience<br />
<a name='more'></a><br />
Here is two ways to manage transactions in spring:<br />
<div>
<br /></div>
<span style="font-size: large;">1) Programmatic transaction with TransactionTemplate class</span><br />
<br />
this means that you have to manage the transaction with the help of programming. That gives you flexibility, but it is difficult to maintain.<br />
<br />
-here is typical example:<br />
<br />
<pre class="brush: java;">TransactionTemplate txTemplate = new TransactionTemplate(txManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
txTemplate.execute(new TransactionCallback<object>() {
public Object doInTransaction(TransactionStatus status) {
// do stuff
}
});
</pre>
<br />
-be aware that <span style="background-color: white; font-family: "arial"; font-size: 13.3333px;">A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template (see TransactionTemplate source in references). </span><br />
<br />
<span style="font-size: large;">2) Declarative </span><span style="font-size: large;">transaction</span><span style="font-size: large;"> </span><span style="font-size: large;">with @Transactional annotation</span><br />
<br />
this means you separate transaction management from the business code. You only use annotations or XML-based configuration to manage the transactions<br />
<br />
-default <a href="http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html">propagation </a> is Propagation.REQUIRED<br />
<br />
-default configured to rollback just Unchecked exceptions (ex RuntimeException), to rollback Exception need to use it like this:</div>
<br />
<pre class="brush: java;">@Transactional(rollbackFor = Exception.class)
</pre>
<br />
-also method should be public, spring will wrap your method with proxy on context start and
will add commit/rollback logic, that is how transnational annotation magic works.<br />
<br />
-call to transnational method should be made from different class not from the same class,
it is limitation of CGLIB (library that is doing method wrapping by the way you can
use <a href="http://stackoverflow.com/questions/3423972/spring-transaction-method-call-by-the-method-within-the-same-class-does-not-wo">AspectJ</a>)
<br />
<br />
-exception saying that "the transaction was marked as rollback only" it is because setRollbackOnly() method was called by exception (by the way you can call it too using previous approach), you can prevent it like this, or start new transaction for each part that should be handled independently<br />
<br />
<pre class="brush: java;">@Transactional(rollbackFor=MyException.class, noRollbackFor=MyException2.class)
</pre>
<br />
-the Service is the best place for putting @Transactional<br />
<br />
References:<br />
<a href="http://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/transaction.html">16. Transaction Management</a><br />
<a href="https://github.com/spring-projects/spring-framework/blob/master/spring-tx/src/main/java/org/springframework/transaction/support/TransactionTemplate.java">TransactionTemplate.java source code</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-14238606332675438672017-01-20T19:45:00.000+02:002017-01-20T19:45:18.859+02:00JDK 9 Is Feature Complete!<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://dzone.com/articles/jdk-9-is-feature-complete">https://dzone.com/articles/jdk-9-is-feature-complete</a></div>
Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0tag:blogger.com,1999:blog-4098043777173851852.post-74312550239109202042016-12-24T23:36:00.002+02:002016-12-24T23:36:58.407+02:00Is Inheritance Dead? A Detailed Look Into the Decorator Pattern<a href="https://dzone.com/articles/is-inheritance-dead">https://dzone.com/articles/is-inheritance-dead</a>Sergeyhttp://www.blogger.com/profile/00026065169994713988noreply@blogger.com0