Where put /resources/ in Spring MVC ? Using application.properties - spring

I am using Spring MVC to create my WebSite.
But I dont understand how/where put my resources if I want to used application.properties instead of xml configuration.
I have enable #EnableAutoConfiguration tag in my project.
I have this project structure.
I'm using JSP like this:
<img src="/images/logo-ack.png" style="width: 60%;">
How I can access to this resources setting the path on application.properties?

You can use Spring initializr for this, because it will starts a project with structure offered by Spring. The website is https://start.spring.io/

Related

Spring boot web app - not able to pick the static content

Spring boot web app with angular bundle was working fine earlier
Then I added a gradle dependency which is a library that is built within my organization to achieve some api calls. And after that the view/angular build is not picking up by spring boot application.
My project structure looks like below
web-app\
src\main\java\
WebApplication.java
\resources\public\index.html
\public\main.5214684651aera5146.js
\public\styles.3asd44654e1asd135fsdf.js
\public\other-angular-build-files
application.properties
I haven't added any view controllers/resource handlers by implementing WebMvcConfigurer. Spring boot was able to pick the index.html file as welcome page and I was able to see the page on http://localhost:8080.
But now it is not working, I have gone though below article and tried with different location of view - public, static, resources, META-INF\resources but nothing workout.
https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
Can someone help how can I debug this issue or override MVC config so that my spring boot should pick the index.html as the welcome page.
In addition to M. Deinum answer you can try to restrict #ComponentScan only in your app and manually create beans from classes from library

Simple REST service with Spring framework not using Spring Boot

I want to start with the most simple Maven Project with a simple REST resource not using Spring Boot and generate a .war artifact that is deployed in a servlet container. I am using Eclipse IDE. So I would like to know what is the basic things in place needed to create such a Project.
I think I need at least this dependences:
Spring-core, Spring-mvc, Spring-web, Spring-context,
I also need the stuff with a class annotated with the #RestController annotation, with some method annotated with the #Requestmapping and so.
But whats the minimum content I should have in the WebContent directory and its subfolders META-INF, WEB-INF ... in order to the servlet container to know how to use the .war component? I dont want any HTML nor JSP pages.
In your WEB-INF folder, you will need a web.xml file. This is where you will configure your dispatcher servlet. This is the part of your application that receives requests and delegates them to the appropriate part of your application.
You will also need some sort of REST configuration file. You can define beans for Spring and component scan config.
A good explanation of this can be found here, https://www.programming-free.com/2014/01/spring-mvc-40-restful-web-services.html

Cannot locate any file inside templates folder from browser

I've made some thymeleaf templates and want to use it with Spring Boot (on Tomcat) and the only location inside a project where I can find a .html file from browser is src/main/resources/static. When I place a file there, I can access it with contextRoot/filename.html. But when I place it inside src/main/resources/templates folder, I cannot access it with neither of this: root/filename.html, root/resources/filename.html. What's the problem here?
Problem was that I didn't have Spring Boot Thymeleaf Starter dependency in the POM. I had plain Thymeleaf dependency not intended for Spring Boot and using it needed more configuration unlike the first one that works out of the box.

Proper place to put static resources in my Spring Boot project

In my Spring Boot project I cannot get static resources such as css, images and java script file via web browser. Where is proper place to put whole bootstrap dictionary, or how to configure to get desired resources?
Just create static folder in src/main/resources here: https://github.com/bajdekm/MailingHero/tree/master/src/main/resources and place them all there. If you don't create controller with mapping to root resource (something like #RequestMapping("/")), spring boot will serve static content from index.html automatically.
Here is relevant section of Spring Boot documentation.

Spring Security Namespace

I am new to Spring Security and I was trying to add spring security namespace. Do I need to add this to serverlet-context.xml. In my Eclipse>Spring MVC project it looks like that is the only file that has namespace information. The other two xml files are web.xml & root-context.xml.
Where do I put the namespace information?
It will depend on how your app is split up and what you want to secure. The web.xml file is not a spring configuration file so you can't put Spring Security configuration in there. Putting it in the servlet-context.xml should be OK.
However, if you are at this stage, you should probably start with one of the sample applications. Also take a look at this getting started guide on spring.io which uses Java configuration with Spring Boot which is a much nicer combination.

Resources