Idea下配置application启动Springmvc项目

文章详细介绍了如何在IntelliJIDEA中配置Springmvc项目,包括ProjectStructure的各个部分如Modules、Libraries、Facets和Artifacts的设置,以及如何配置application启动,特别强调了VMoptions和Mainclass的参数。此外,还提及了Tomcat的配置文件,如端口设置和SSL/TLS连接器。

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>
IntelliJ IDEA配置应用程序的环境变量,可以通过运行配置(Run/Debug Configurations)进行设置。这种方式允许为特定的应用程序指定环境变量,而不会影响全局系统环境变量。 ### 配置应用程序环境变量的步骤如下: 1. 打开 **Run/Debug Configurations**: -IntelliJ IDEA 的右上角点击运行配置下拉菜单,选择 **Edit Configurations...**。 2. 添加新的运行配置- 如果尚未创建运行配置,点击左上角的 **+** 号,选择对应的应用类型(如 Application、Spring Boot 等)。 3. 设置环境变量: - 在运行配置窗口中,找到 **Environment variables** 字段。 - 点击右侧的编辑按钮(通常是一个小齿轮图标),打开环境变量编辑对话框。 - 在对话框中,点击 **+** 号,添加需要的环境变量名称和值。 - 例如: - 变量名:`APP_ENV` - 值:`development` 4. 应用并保存配置- 点击 **Apply**,然后点击 **OK** 保存配置。 ### 示例配置 如果需要设置多个环境变量,例如 `APP_PORT=8080` 和 `LOG_LEVEL=DEBUG`,可以在 **Environment variables** 字段中直接输入: ``` APP_PORT=8080;LOG_LEVEL=DEBUG ``` ### 使用代码获取环境变量 在 Java 应用程序中,可以通过以下方式获取环境变量: ```java public class Main { public static void main(String[] args) { String appPort = System.getenv("APP_PORT"); String logLevel = System.getenv("LOG_LEVEL"); System.out.println("Application Port: " + appPort); System.out.println("Log Level: " + logLevel); } } ``` ### 注意事项 - 环境变量的设置仅适用于当前运行配置,不会影响全局系统变量。 - 如果需要为不同的运行配置设置不同的环境变量,可以分别配置各自的运行配置- 确保输入的环境变量名称和值正确无误,避免因拼写错误导致程序无法读取。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值