im new to Java Spring and when i am starting netbeans with a new web project, i have the option to choose a framework. When I'm choosing Spring MVC, i have got an embedded tomcat out of the box. I liked it very much! So easy it can be! But this make it complicated to understand what is happing behind. I want to know, how to create a https connection, without configuring in the tomcat settings. (Or is this the only way?) I tried this one, but than you have to start tomcat manually with the batch-file. When using http-connection und you running your project it usally reachable and you do not need to start tomcat! I dont know how it works, but i think it starts the embedded tomcat and listing to a random port, the url is printing out when starting project. Another question is, where can i change the url name? Now i have this one:
http://localhost:8084/projectname/
And i want to give a customer name. Maybe someone answer to this question or post a link with useful information how to configure embedded tomcat. For me it is important to keep the default construction of java spring in netbeans!
And i want to use the dispatcher.xml, web.xml -> So don't want to switsch to use tomcat in my javacode! Hope that this is possible!
Thank you very much, Mira.
Related
I have a web app built with Java, Spring MVC, and JDBC. The result is a WAR file.
To run it, the user has to install Java 8 JDK and Tomcat, and deploy the WAR file to the Tomcat server.
It would be great if they could just download the one file run it as a standalone application.
That is, run "the WAR file" and just browse to http://localhost:8080/myapp
Also, on Windows it would be great it was setup as a Server (like Tomcat is when installed with the installer).
Is there any way to do this? Maybe with Spring Boot or something new like that?
Yep, Spring boot is the way to go.
It allows you to build an executable Jar with all dependencies and a Tomcat (by default, can be changed) embedded.
But users will still need to download a JRE to execute the Jar, and a database if it's required, but you can use en embedded database like H2, HSQLDB..., depends what is your needs.
Yes . you can use spring boot to achieve your results. Kindly refer the below link for sample code
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/
You can use embedded jetty server using maven but that would require you to setup few things your app and may have align your existing app, please check this article for more information.
Jetty is similar to tomcat server in terms of running spring application, there are not much difference in terms of development. Tomcat is just more famous.
Other option as others said, is to migrate your app to spring boot which would be easy if you already have app written in spring (But that depends how much code you have and how much time you have)
I have just returned to Spring after 5 years of gap and it seems lot is changed. I have a task to create a REST Service using Spring with hibernate as an ORM, So far I am able to run a basic Rest Service using embedded jetty and able to make GET/POST calls, the next is to integrate hibernate into it so that the data fetch/Sent operation actually use MySQL instead of sending hard-coded response(which I have done currently).
The issue is earlier I used to work on Spring MVC using Tomcat where we had web.xml to define the dispatcher servlet and application-context which in turn were used to define hibernate config and other beans declaration, but now having embedded jetty I am not finding a way to integrate hibernate to my REST app, Is the way to add configuration is changed from XML to class based config. I searched over internet but maybe I am out of words or not using correct keywords, in short, Have no luck finding some solution to integrate hibernate to my Spring app which is using embedded jetty.
Could some please breif me about the recent changes or point me to the right tutorial ?
Any help appreciated, thanks in advance !
ps - I have used this example to progress so far https://github.com/pethoalpar/SpringMvcJettyExample
Yes , lot of changes in these 5 years and one of the game-changer is spring-boot
If you want to build a brand new project especially if you want to run the web application on the embedded container such as Jetty , you can check out spring-boot.It already provides integration with Jetty , hibernate and Spring MVC REST service.
The end result is that you just need to change a little bit configuration (most probably the DB connection info) and you can quickly get a production-ready REST service backed by JPA/Hibernate which can just run without any XML configuration anymore.
There are tons of tutorials in Internet talking about how to do it . You should easily find them out such as this using the keywords something likes "springboot webservice hibernate jetty" etc.
There is an application, say myApp.war (developed using Spring MVC) that I give the users to deploy in their tomcat webapp folder. When the user starts tomcat, the war is exploded, and then I ask the user to go myApp/WEB-INF/classes/persistence.properties and ask him to edit just one property name (actually an HSQLDB path). Post that I ask the user to stop tomcat, delete the war file and start tomcat server again. And the application is up and running.
Although the users are not complaining, I believe there has to be a better way of doing this. For example when the users deploy wordpress or hudson and the first time they try to access the app. they are redirected to an install page where they do their basic configuration and they are up and running. How can I achieve it here.
I have used JNDI to solve this very problem in the past. Here is a nice example to show you how to do this with Spring:
http://www.journaldev.com/2597/spring-datasource-jndi-with-tomcat-example
Checkout JMX which can allow on the fly configuration, or there is one obix framework
Why not something like this:
Use a relative path with sysprops, like ${user.home}/path-to-hsqldb. If the user runs tomcat as user "jim", it will look in c:\users\jim\path-to-hsqldb (Windows) or /usr/jim/path-to-hsqldb (Linux)
You might need to use Spring's <context:property-placeholder/> to enable this.
I have not been able to find any documentation on how to setup an ehCache server embedded inside an existing application. Does anyone know of a way of doing this?
It is working not as a server but it is simple library. In this case usage is pretty simple:
http://www.ehcache.org/documentation/2.8/code-samples.html
All you need - configure ehcache.xml.
Yes, there is also a server, in form of separate web-app. So you can just take this web-app and run on embdeded jetty.
According to Spring documentation, it's possible to configure an embedded ApacheDS server, which makes testing easy.
Any reason why not use ApacheDS embedded with spring in deployment? is there some kind of limitation for that?
Also I noticed it's writing to temp directory /tmp/apacheds-spring-security. Is there a way to configure it?
I already participated in a project where embedded ApacheDS server was used in development and deployment (for test server). There was two minor problems:
If you stop your app incorrectly (for example via Terminate in debug mode or via kill -9) then you need to clean up /tmp/apacheds-spring-security directory manually. If you leave temporary files then an runtime exception will be thrown during next loading of your app.
We did not find how to change the default temporary directory (/tmp/apacheds-spring-security).
Hope this helps.
EDIT.
For the first problem I ended up with a servlet-api listener. It was declared before Spring context listener (to ensure execution before Spring and ApacheDS). This listener was responsible for checking and cleaning up /tmp/apacheds-spring-security. Maybe it is not the most elegant solution but it works. It will be better to have a param for this case in ApacheDS, something like -DapacheDSCleanUpWorkDirAtStutup=true.