I've recently solved a problem of locating images in this community. You can look here.
However, one answer said:
Your app is a Spring Boot app. I think that you can also try to use the facilities provided by Spring Boot for serving static content. Anyway, you are doing it right now because you are using webjars for css and js libs!!! Be consistent with the tech that you are using.
This means, it's recommendable to locate the images files in /src/main/resources and not in /src/main/webapp.
How could i use the facilites that Spring Boot provides me?
Thanks
Spring Boot automatically configures production-ready settings and adds beans to your Spring project based on some dependencies that are declared in your maven/gradle build file. As long as you follow the conventions, then you do not have to do so much configuration -- "convention over configuration". For example, one convention is to load your images and static files in the resource classpath. Refer to the documentation: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
Related
I am new to generating javadoc and confused about the following issues with javadoc generation in Spring Boot apps:
Should I add class definition to each class in the application? Could you give a definition example for Controller classes?
I am using IntelliJ Tools > Generate Javadoc menu with the default choices and choose javadoc directory in the resources folder. Is there a better way for generating javadoc and keeping them in a Spring Boot app (I use resources/javadoc folder, but not sure if there is a proper way as a convention for this).
we just use swagger
visit locol like:
http://localhost:8080/swagger-ui.html
I am currently building a library or API which will be used by another Spring REST application, below are the advantages I thought of using Spring.
Spring flow(Context initialization->Post construct)
Easy way of reading properties file
Autowiring and bean management
Rapid development
Below are the disadvantage
Tightly coupled, the main application which is going to use the library/API has to import or refer the configuration class of library in order to initialize context
Main application has to use Spring(considering use in other projects)
Is there anything I am missing, can Spring framework be used to develop API or library?
Note: The number of library to build is 3-5 and will grow in future.
The only reason to use spring you are giving, is to benefit from the building of the application runtime.
I do not see it as a great advantage from spring for a library : it is only replacing a few new and set statements, that could be easily explained in a doc, with even some sample bean declaration for the users of your api, if he wishes to init your lib in a spring context.
One of the drawback you are not giving is the support of multiple versions of spring by your library :
what will happen in one / two years, when an old application developped using your library will need small enhancements, but still be on spring v4, but new application will import spring v6 (with no resource to migrate old app on spring v4 to latest version) ?
So i would use spring in a library only if you need to participate in database transaction of the main application (and other tasks like this where it is really convenient to use spring), but otherwise try to depend as little as possible on spring.
EDIT:
Even when minimising the use of spring in the runtime of your library, you can use it extensively to test your library.
The spring context instead of being included in the resource of your lib is only a test resource, which you can use to bootstrap spring-test, for example.
Helo everyone!
I completed my Spring based web app and then started to rebuild it to Spring boot because it gives me ability to use embedded jetty.
At the moment I got some problem - Spring boot can not find (resolve) jsp views. So when I run my app - I get the error in browser:
Here is my web app on github - so you can just look at files and find the reason.
Help me please!
P.S. Yes I used #ResourceImport because I don't know how to rewrite the existing spring configuration xml files to java-based config files but you may show me HOW to do that in your answer.
P.P.S. And for some reason the target directory does not contain WEB-INF and it's content folders after compiling. May be this is the reason but I don,t know how to solve it!
I checkout-ed your code from github and managed to deploy into embedded Tomcat 8.0.3 and standalone Tomcat 8.0.x.
I will just go through the steps for embedded Tomcat instead of Jetty(as I have not figured out the Jetty configuration fully yet).
There are two things that you could do
Copy your webapps into the following location without the s, e.g. /dvdexchange-spring-boot/src/main/webapp
Modify slightly your pom.xml, e.g. below
The final outcome as below
-
UPDATE:
IngeniousTom,
I was not able to make it work in embedded Jetty, the furthest point I could reach after struggling to add numerous Maven Jetty jar libraries as shown below
This is actually a known issue and I do not see how this can be solved without any hackish way.
If you read in the github link, there is numerous discussion between Spring-Boot and Jetty camps.
The bottom line of the discussion is that Spring-Boot does not support yet Jsp in embedded Jetty as their standard but have plans in future.
My recommendation is not to use Jsp or use other than Jetty as your embedded container.
JSPs in executable JARs are not officially supported by Spring Boot, this is one of the known JSP limitations. Also, Spring Boot supports JSPs in embedded Jetty as of 1.4.0.RC1, not before.
Right now you can solve this by using Spring Boot 1.4+ and packaging your application as an executable WAR. You'll be able to deploy your app as a regular WAR, run it with java -jar app.war and have a nice development experience - all of this with standard JSPs.
Maybe you'll find tricks to work around those limitations, but keep in mind that those often rely on container-specific behavior that aren't supported by the servlet spec. So at best, this behavior will be inconsistent between containers - and it's certainly possible that containers may change their behavior at any time.
If you really want to package your app as an executable JAR, then the best approach is not to use JSPs and pick a proper template engine.
If you want to do a jar-Deployment you cannot use the wepapp folder.
Put your JSPs to src/main/resources/META-INF/resources/jsp
Put these lines to your application.properties file:
spring.mvc.view.prefix=/jsp/
spring.mvc.view.suffix=.jsp
You can have a look to this project. It also uses Spring-Boot, a jar-Deployment and JSPs: https://github.com/synyx/urlaubsverwaltung
I'm trying to design the architecture of a medium-sized web application in Java and I would like to get some advice on how to do it.
The project consists on a base website plus a number of modules. For instance, one module would provide user registration, another module would offer a web service, and so on...
Whenever I need to deliver the application to a new customer, the ideal thing would be to pick up the modules he wants, do some theming (css, images, maybe jsp) and developing the custom modules he may need, if any.
I've taken a look to maven multi module projects, war overlays, but I find it difficult to partition the application, especially in regard to the modules' configuration (for example, merging a global spring configuration from the modules). Can somebody point me to an example of such a system? Thanks in advance!
merging spring configuration is easy. In each module, package up a spring context file in it's /WEB-INF/classes directory. When you overlay, all classes and resources in WEB-INF classes in the dependency will be put into WEB-INF/classes in your app. (ps, this also works if you package as .jar instead, but you won't be able to overlay .jsp files if you do)
Then it's just a matter of importing them. This is best done by using a set pattern to find the files. Here's an example:
<import resource="classpath*:/module/*-context.xml" />
This will import all the classpath resources that match this pattern.
Annotation based example:
#Configuration
#ImportResource(value={"classpath*:/module/*-context.xml"})
public class MyConfiguration { ... }
It's the web.xml configuration that will cause you more trouble than anything if you have the need to do any web.xml customizations in modules. You could use servlet 3.0 for this of course, but it requires the right server to deploy on.
fwiw, after some experience with plain Spring import we developed tiny framework for osgi-less modularity for Spring. The first problem with import is the bean name clashes you can not have same-named singleton in two contexts, and many other hassles.. tbc https://github.com/griddynamics/banshun
--
Mike
I have a Java/Spring/Hibernate application with a payment module. Payment module has some domain classes for payment subscription and transactions etc. Corresponding hibernate mapping files are there. This module uses applicationContext.xml for some of the configuration it needs.
Also, This module has a PaymentService which uses a paymentDAO to do all database related work.
Now, I want to use this module as it is(without any or minimal re-writing) in my other application(Grails application). I want to bring in the payment module as a jar or copy the source files to src/java folder in Grails.
With that background, I have following queries:
Will the existing applicationContext.xml for Spring configuration in the module will work as it is in Grails? Does it merge with rest of Grails's Spring config?
Where do I put the applicationContext.xml? classpath? src/java should work?
Can I bundle the applicationContext.xml in Jar(If I use jar option) and can overwrite in Grails if anything needs to be changed? Multiple bean definition problems in that case?
PaymentService recognized as regular service? Will it be auto-injected in controllers and/or other services?
Will PaymentDAO use the datasource configuration of Grails?
Where do I put the hbm files of this module?
Can I bundle the hbm files in Jar(If I use jar option) and can overwrite in Grails if anything needs to be changed? Which hbms are picked? or, there will be problems with that?
Too many questions! :)
All these concerns are actually before trying. I am going to try this in next few days(busy currently). Any help is appreciated.
Thanks.
There are a couple of things you'll want to consider:
You'll need to package your applicationContext.xml to avoid namespace clashes - that is, you'll probably put it in src/resources/com/company/module/applicationContext.xml
This application context really needs to be compatible with the grails application - it'll need to access the DB connection used by your app - make sure it doesn't define its own - See section 14 of the docs - http://grails.org/doc/latest/guide/14.%20Grails%20and%20Spring.html
Section 15 of the docs - http://grails.org/doc/latest/guide/15.%20Grails%20and%20Hibernate.html describes using hibernate mapping files
15.4 points out some good articles - http://jasonrudolph.com/blog/2006/06/20/hoisting-grails-to-your-legacy-db/ and http://www.infoq.com/articles/grails-ejb-tutorial
Probably not the exact answer you were looking for, but I hope this helps.