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
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.
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.
Then find a pom.xml file, click on it and select Add maven project.
Now it will download all needed dependencies and prepare 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
File -> project structure
and set your installed JDK.maven
button at the right panel and click on reload button.mvn install:install-file -Dfile=repo/markdown4j-2.2.jar -DgroupId=org.markdown4j -DartifactId=markdown4j -Dversion=2.2 -Dpackaging=jar
test
to mysql and add user root
with password root
or change settings in the file application.properties
.Blog3Application.kt
and selecting Run ru.vir...
.main] b.Blog3Package$Blog3Application$ecf5ead7 : Started Blog3Package.Blog3Application.ecf5ead7 in 54.823 seconds (JVM running for 60.337)
.
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.
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")
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.
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.
Hello!
I've updated my Kotlin to new version 1.0.0-beta-1038.
Steps:
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
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: