Idea下配置application启动Springmvc项目

Idea配置application启动Springmvc项目

配置整体工程(注意:三个编译目录重要!!!)

1.首先进入File–>Project Structure…目录下
在这里插入图片描述

2.设置Project Setting–>Project,此处主要配置工程的相关信息

3.设置Project Setting–>Modules,此处主要对模块下的文件进行资源标记

在这里插入图片描述

在这里插入图片描述

4.设置设置Project Setting–>Libraies,此处主要

在这里插入图片描述

5.设置Project Setting–>Facets
在这里插入图片描述

6.设置Project Setting–>Artifacts

在这里插入图片描述

配置application启动

1.首先编辑application配置

在这里插入图片描述

2.打开如下界面,在右侧进行参数设置

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qV4mPvYg-1675936017389)(C:/Users/xiaoxiao/AppData/Roaming/Typora/typora-user-images/image-20230208181639534.png)]
以上Main class如果报错记得把tomcat的以下包加入进来
在这里插入图片描述

参数如下

VM options:

-Dcatalina.home="D:\zixuan\source\tomcat8\tomcat8"
-Djava.endorsed.dirs="D:\zixuan\source\tomcat8\tomcat8\common\endorsed"
-Dcatalina.base="D:\zixuan\source\tomcat8\tomcat8"
-Denv.host="http://192.168.1.100:92"
-Denv.ahost="http://192.168.0.200:82/attach"

Main class:

org.apache.catalina.startup.Bootstrap

Program argument:

-config
"D:\zixuan\source\tomcat8\tomcat8\conf\devlop_future_t_server_idea.xml"
start

Working directory:

D:\zixuan\development\java\ideaproject\devlop_future

开发环境:

spring.profiles.active=dev

** 补充**
在这里插入图片描述

在这里插入图片描述

tomcat项目配置文件

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
    maxThreads="150" minSpareThreads="4"/>
-->


<!-- A "Connector" represents an endpoint by which requests are received
     and responses are returned. Documentation at :
     Java HTTP Connector: /docs/config/http.html
     Java AJP  Connector: /docs/config/ajp.html
     APR (HTTP/AJP) Connector: /docs/apr.html
     Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="83" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8446" maxHttpHeaderSize ="102400" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
           port="8081" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
-->
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
     This connector uses the NIO implementation. The default
     SSLImplementation will depend on the presence of the APR/native
     library and the useOpenSSL attribute of the
     AprLifecycleListener.
     Either JSSE or OpenSSL style configuration may be used regardless of
     the SSLImplementation selected. JSSE style configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true">
    <SSLHostConfig>
        <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                     type="RSA" />
    </SSLHostConfig>
</Connector>
-->
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
     This connector uses the APR/native implementation which always uses
     OpenSSL for TLS.
     Either JSSE or OpenSSL style configuration may be used. OpenSSL style
     configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
           maxThreads="150" SSLEnabled="true" >
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
    <SSLHostConfig>
        <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                     certificateFile="conf/localhost-rsa-cert.pem"
                     certificateChainFile="conf/localhost-rsa-chain.pem"
                     type="RSA" />
    </SSLHostConfig>
</Connector>
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<!--
<Connector protocol="AJP/1.3"
           address="::1"
           port="8009"
           redirectPort="8443" />
-->

<!-- An Engine represents the entry point (within Catalina) that processes
     every request.  The Engine implementation for Tomcat stand alone
     analyzes the HTTP headers included with the request, and passes them
     on to the appropriate Host (virtual host).
     Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">

  <!--For clustering, please take a look at documentation at:
      /docs/cluster-howto.html  (simple how to)
      /docs/config/cluster.html (reference documentation) -->
  <!--
  <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  -->

  <!-- Use the LockOutRealm to prevent attempts to guess user passwords
       via a brute-force attack -->
  <Realm className="org.apache.catalina.realm.LockOutRealm">
    <!-- This Realm uses the UserDatabase configured in the global JNDI
         resources under the key "UserDatabase".  Any edits
         that are performed against this UserDatabase are immediately
         available for use by the Realm.  -->
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
           resourceName="UserDatabase"/>
  </Realm>

  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
	<Context path="/" docBase="web目录全路径" reloadable="false" autoDeploy="true"/>	   

  </Host>
</Engine>
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置SpringMVC项目需要按照以下步骤: 1. 在IDEA中创建一个新的Maven项目。 2. 在pom.xml文件中添加SpringMVC的依赖,如下所示: ```xml <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.9.RELEASE</version> </dependency> </dependencies> ``` 3. 在src/main/webapp目录下创建WEB-INF目录,并在该目录下创建web.xml文件。在web.xml中配置SpringMVC的DispatcherServlet,如下所示: ```xml <web-app> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springmvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> ``` 4. 在src/main/webapp/WEB-INF目录下创建springmvc-config.xml文件,并在该文件中配置SpringMVC的组件扫描和视图解析器,如下所示: ```xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="com.example.controller" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> </beans> ``` 5. 在src/main/webapp/WEB-INF目录下创建views目录,并在该目录下创建jsp文件,如下所示: ```jsp <html> <head> <title>Hello SpringMVC</title> </head> <body> <h1>Hello SpringMVC!</h1> </body> </html> ``` 6. 在src/main/java目录下创建Controller类,并在该类中添加@RequestMapping注解,如下所示: ```java @Controller public class HelloController { @RequestMapping("/") public String hello() { return "hello"; } } ``` 7. 运行项目,访问http://localhost:8080/,即可看到Hello SpringMVC的页面。 以上就是配置SpringMVC项目的步骤,希望可以帮助到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值