Answer the question
In order to leave comments, you need to log in
What are the options for running spring-webmvc?
Good day.
I'm learning Spring Framework and tried different variations of its usage.
There are many variations of running Spring-based applications, it's easy to get confused.
I bought the course in the hope that after the course, everything will fall into place and a deeper understanding of Spring will come).
In the course, the project is created in IDEA using the maven archetype: maven-archetype-webapp.
But the problem itself is that the author of the course uses IDEA Ultimate, which of course I don't have (already). (In the course, the author connects TomCat.)
Is it possible to run this project using Spring tools, without using IDEA Ultimate, and if so, how?
What dependencies in pom.xml need to be included, and how to configure, so that everything would work?
Project structure from the course:
Files:
HomeController.java:
@Controller
public class HomeController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
public ModelAndView home() {
return new ModelAndView("index"); } }
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<context:component-scan base-package="org.example"/>
</beans>
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.example"/>
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".html"/>
</bean>
</beans
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:app-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>my-dispatcher-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfiguration</param-name>
<param-value>classpath:web-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>my-dispatcher-servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<type>maven-plugin</type>
</dependency>
Answer the question
In order to leave comments, you need to log in
1) Yes, I agree. (meaning that it can connect the built-in serv.)
2) sorry)
.
3) Good, I agree. Now for me, all the use of maven is to connect dependency and only, it would be nice to understand it in more depth ..
4) Spring Boot IDEA is not needed to start - this is understandable.
SpringBoot - based on the Spring Framework, and by connecting one spring-boot-* ..-starter, you can immediately connect a bunch of libraries (including, of course, there will be libraries with the Spring Framework) and + all the SpringBoot goodies, auto configuration and other..
- So .. it means theoretically it is possible, if you analyze Spring''à well enough, and connect to such a project only what is necessary to run it like with SpringBoot .., but without any additional. dependencies that it automatically connects ..
After all, the main feature of SpringFramework is its maximum flexibility, which means that theoretically there should be a way by connecting something else, so that it would work like SpringBoot - but without its additional . dependencies.
Thanks for the page.
I didn't even think about SpringTools4 for IDEs. I saw they write that there is some kind of "helper tool" for Spring, for Ecipse and that's it, but it turns out that it is also for Visual Studio. Should be o.k. useful, ok we'll see, we'll try.
UPD: it was necessary to add a trace. dependencies..
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
1) Spring doesn't start anything by itself - it's a framework.
2) No need to jump from one lesson to another. You won't be able to cross a snake with a hedgehog
3) Learn maven.
4) If you want a quick start, then start with SpringBoot, it's easier. To start SpringBoot IDEA is not needed, everything is done within the maven framework.
And yes, use the official documentation.
Specifically here is the IDE choice page
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question