Spring MVC Template Location - spring-mvc

Spring boot stores in template files in /src/main/resources
Where is this configured and how can I get Spring MVC to do this when not using Spring Boot?

In Spring Boot templating is usually configured via autoconfiguration, which takes information from application properties. For instance Thymeleaf template location can be configured like this:
spring.thymeleaf.prefix=classpath:/templates/ # Prefix that gets prepended to view names when building a URL.
See Spring Boot properties reference for more details.
Without using Spring Boot you can configure the same behavior by specifying custom ViewResolver bean and specifying prefix for templates. You can take a look at ThymeleafAutoConfiguration for inspiration.
Same principles apply to using other templating engines than Thymeleaf with Spring MVC.

Related

Spring Boot jar into existing Spring Project

We have an existing Spring MVC based application. I was asked to plug-in a customization/utility to this project. I am not supposed to do any changes to the existing application.
For the new utility, I thought of doing it through a Spring boot jar. I created a Spring boot jar and placed in the lib folder of the existing application. However, I am facing few issues with this approach and wanted to know if this is the correct approach and if there are any suggestions out there. The issues are:
The logging level of the Spring boot affects the logging level of the existing application. How can I avoid that?
The Spring MVC application and the Spring boot jar both are based on different versions of Spring. What if there are some common class files or packages in both Spring MVC application and the Spring boot jar but with different versions? Will this create any conflicts or will it affect the functionality? I don't want my Spring boot jar to affect the functionality/logging of the existing application. I just want the Spring boot jar to work whenever it is being called explicitly.
For logging issue, I have tried to use something like below in application.properties file but the issue with that is that those settings are considered only if you run the application through #SpringBootApplication main class. But if you just want to package your functionality in a jar file then the application.properties file is not considered.
logging.level.org.springframework = OFF

Can we reuse spring MVC filters in Spring WebFlux apps

I am new to spring WebFlux and understand that the way we write filters in Spring WebFLux is different from the way it is written in Spring MVC (ServletFIlter , HandlerInterceptor) . We have some Spring MVC Filters already written , can we reuse it in Spring WebFlux , or do we have to rewrite it .
Yes, you'll have to rewrite them. Spring-Webflux defines their own equivalents, with Reactive types. There's WebFilter class replacing functionality of ServletFilter and HandlerInterceptor classes.
The reason is simply that WebFlux is not following the Servlet specification, for better reactive support.

How can I add webflow using Spring Boot and Thymeleaf?

I have written a Spring web app for baseball umpires using Spring Boot and Thymeleaf. I like Spring Boot because it resolves dependency w/o a lot of configuration. Now I want to add Sprng WebFlow so umpires can order uniforms, a typical "shopping cart" application. There are many examples on the web but none using Spring Boot. They all are the traditional xml config with jsp and jstl. Has anyone used Spring Boot and WebFlow? There are WebFlow examples on the official Spring web site but very complicated. Thanks Rob
Spring Roo 2.0.0.M3 generates Spring Boot applications and integrates Spring Web Flow easier than ever.
The reference guide includes detailed descriptions of all the features, plus an extensive user guide for main use cases.

Connecting Spring + JPA web application with MySQL

I have been reading how to make web application using spring from the Getting Started Guides, specifically the following guides:
Serving Web Content with Spring MVC
Accessing Data with JPA
But I could not figure how the JPA selected which database driver to store data into.
How can I connect to MySQL database in Spring + JPA.
I learned about Spring + Java Annotations (No XML configurations)
The guides you mention all use Spring Boot.
Spring Boot is a new Spring project that is used for bootstrapping Spring projects. In your case it will auto-configure the datasource for you. Specifically if you have H2 or HSQL on the classpath, Spring will create that in-memory database.
You can easily override the defaults provided by Spring Boot by adding the following properties to application.properties:
spring.datasource.url=jdbc:mysql://whateverhost/whateverdbname
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driverClassName=com.mysql.jdbc.Driver
For more information check out the relevant documentation.
Or you can check out this tutorial

Does Mule supports Spring MVC?

I have web app which is already developed based on Spring MVC. I need to re-implement that web app in Mule.
Can I develop the mule application based on Spring MVC?
Can I declare the Spring MVC dispatcher servlet inside a mule's servlet endpoint and take things further from there?
The web app has web.xml where it defines the DispatcherServlet, the contextparams, the listener classes and so on. How can we remodel that in a mule application?
Any examples where a mule application is developed based on SpringMVC would be great.
Thanks to its embedded Jetty container, you can deploy any JavaEE web application in Mule. So there's no need to remodel anything.
The "Boosktore" example application demonstrates running web-apps within Mule: https://github.com/mulesoft/mule/tree/mule-3.x/examples/bookstore
Mule ESB is not an MVC Framework. It is developed using enterprise integration patterns in mind.
Please go through this blog, to know when to use ESB.
spring mvc can be integrated with mule.
Define all your spring related configuration in separate xml file and include it in mule configuration file.
You can write your custom transformers ,in the custom transformations you can inject or do an autowire of your service classes and from service object you can interact with dao layers.

Resources