Hello world! I'm a bit known as Virtustilus

Started at 2015-05-20

In this blog I'm going to show you, how to use Spring Boot and compare it to symfony2 framework. I'm writing this text right in JTwig template. It's almost good, but I would expose some info how to make your first Spring application with Kotlin language. Next parts of this page are different entities in Markdown format and are loaded from database.

Server restarted at: 2020-07-14 06-24-23, request number from 24 of May 20:00: 67937


JTwig 2015-05-21 05:49:50

About JTwig support

To use JTwig in IDEA you will need additional installed plugin Twig and also IDEA should be Ultimate (this one much more expensive than PHPStorm).

Also I've found one problem regarding support of JTwig - it doesn't support _csrf data by default, so you will need to get this token manually and add it to parameters.


Lets start: how to install Spring with Kotlin language 2015-05-22 06:51:32

Install spring boot

Lets plat with kotlin and spring a bit

Spring Boot provides useful thing to configure modules that you want to add to your project.

I selected next way to do it: install official Spring Tools Suite. Create new Spring Boot project and select needed modules, than open this project in Intellij Idea CE, if you don't like eclipse.

Or even you can download this Blog3 project from bitbucket https://bitbucket.org/virtustilus/virtustilusblog and open it.

Add maven project

Then find a pom.xml file, click on it and select Add maven project.
Now it will download all needed dependencies and prepare project.

Start project

Find the file Blog3Application.kt and right click and select Run ru.vir…

When compiling and starting finished, you will see last line like Started Blog3Package.Blog3Application.4028ac93.

Now you can open your browser on page http://localhost:8080/


If you get some problems just write me: virtustilus@gmail.com


How to open project and build it 2015-05-25 17:26:56

Hello! I think you already set git, mysql, java jdk 7 (or 8)

How to setup blog3 on your new system

  1. Clone the project from bitbucket.
  2. Open it in the Idea.
  3. Open File -> project structure and set your installed JDK.
  4. It will ask to install some plugins, allow it.
  5. Click to maven button at the right panel and click on reload button.
  6. Install additional jar library: mvn install:install-file -Dfile=repo/markdown4j-2.2.jar -DgroupId=org.markdown4j -DartifactId=markdown4j -Dversion=2.2 -Dpackaging=jar
  7. Add database test to mysql and add user root with password root or change settings in the file application.properties.
  8. Now you can try to start the system by right-clicking to Blog3Application.kt and selecting Run ru.vir....
  9. After about 1 minutes you should see last line like main] b.Blog3Package$Blog3Application$ecf5ead7 : Started Blog3Package.Blog3Application.ecf5ead7 in 54.823 seconds (JVM running for 60.337).
  10. Now open the browser with address: http://localhost:8080/ and you should see the page.
  11. You can play with it :)


Spring, Hibernate, Tomcat and Mysql connection timeout 2015-06-06 11:43:24

Every day in the morning I got 500 error page with something like this:

Could not roll back JPA transaction; nested exception is javax.persistence.PersistenceException: unexpected error when rollbacking.

it means that there was some disconnection with mysql server.
By default spring don't reconnect to mysql server and just returns this error. Also another thing is that disconnection was just timeout of connection, when nothing happened during the night.

To fix issues with disconnection and make jpa able to recconnect to database server I added next parameters into application.properties file:

spring.datasource.connection-test-query=SELECT 1
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=true
spring.datasource.validation-interval=10000
spring.datasource.log-validation-errors=true
spring.datasource.validation-query=SELECT 1

Now it works fine, I turned off mysql service by sudo service mysql stop, then opened blog - it returned error. Then I started mysql back and blog is working again.


Updating kotlin to version M12 2015-06-04 07:30:38

How to update kotlin to version M12

At first update your plugin for idea

Next you will need to set correct version in your dependencies in pox.xml file (if you are using Maven):

0.12.200

Then you can automatically fix most parts by Analyze -> Code cleanup in the menu.

Next you should change annotations that has array (just remove word array), for example:

RequestMapping(value = array("/pages/new")) 

should be converted to:

RequestMapping(value = "/pages/new")

Kotlin error with Native2AsciiCharsetProvider

When I finished changing code I got this error at the start of spring:

java.util.ServiceConfigurationError: java.nio.charset.spi.CharsetProvider: Provider com.intellij.lang.properties.charset.Native2AsciiCharsetProvider not found

It was in case of using 1.7 version of Java in dependencies and I changed properties part of my pom.xml file. Set java.version to 1.8:

<properties>
    <kotlin.version>0.12.200</kotlin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>ru.virtustilus.blog3.Blog3Package</start-class>
    <java.version>1.8</java.version>
</properties>

Now project compiles again with new Kotlin M12.


Moved to new data center 2015-10-16 09:10:15

Recently I've removed my Amazon instance and created new account on Digital Ocean
It's faster and not so expensive. Better choice for some development server for me.


Updated Kotlin to version 1.0.0-beta-1038 2015-10-25 18:53:30

Hello!
I've updated my Kotlin to new version 1.0.0-beta-1038.
Steps:

  1. Updated kotlin plugin in IDEA.
  2. Fixed code (annotations, array, sortBy, default value in empty data class).
  3. In pom.xml changed start class and kotlin version.
  4. I also updated to new Java 8 (needed to change it in project structure settings).
  5. Then I deleted old start configurations and right clicked on main file Blog3Application.kt and selected Create “…” configuration. Configuration to start program was automatically created.
  6. Updated maven dependencies.
  7. Started application.
  8. Built package by selecting “clean” and next “Package” in maven menu.
  9. Deployed to server.

All code changes you can find here: https://bitbucket.org/virtustilus/virtustilusblog/pull-requests/1/updated-kotlin-to-100-beta-1038-version/diff, or download latest master branch from my repository:
https://bitbucket.org/virtustilus/virtustilusblog/

Good luck with Kotlin.
Any questions you can leave on my email: virtustilus@gmail.com


Bitbucket issues 2015-10-25 21:02:09

Another one issue with bitbucket: it does't show pull request for not logged in users… weird.
At least you can see commit of most changes for Kotlin update from M12 to 1.0.0-beta-1038:

https://bitbucket.org/virtustilus/virtustilusblog/commits/89adb9219cddb9cf5aa7201f3d6c99b21fc1ef58?at=master