【知识点】springboot项目配置项目访问根路径

SpringBoot中的server.context-path 书接上回,首先,先看一张图片。 阅读详情
AI摘要

本文介绍了在SpringBoot应用中通过application.properties/yml文件、命令行参数和编程方式配置ContextPath,以实现不同应用的URL路径区分。

在Spring Boot中,可以通过配置属性来设置应用的Context Path(上下文路径)。Context Path是URL中应用的根路径,用于区分不同的应用。以下是几种常见的设置Context Path的方式:

1,使用application.properties/application.yml文件配置:

在src/main/resources目录下的application.properties或application.yml文件中,添加以下属性配置:

# 设置Context Path为/myapp
server.servlet.context-path=/myapp

或者在application.yml文件中添加以下配置:

# 设置Context Path为/myapp
server:
  servlet:
    context-path: /myapp

这样配置之后,应用的URL将以/myapp开头。

2,使用命令行参数配置:

在运行Spring Boot应用时,可以通过命令行参数来配置Context Path。例如:

java -jar myapp.jar --server.servlet.context-path=/myapp

这样配置之后,应用的URL将以/myapp开头。

3,使用编程方式配置:

在Spring Boot应用的启动类中,可以通过编程方式来配置Context Path。例如:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.web.context.WebApplicationContext;

@SpringBootApplication
public class MyAppApplication implements ServletContextInitializer {

    public static void main(String[] args) {
        SpringApplication.run(MyAppApplication.class, args);
    }

    @Override
    public void onStartup(javax.servlet.ServletContext servletContext) throws javax.servlet.ServletException {
        String contextPath = "/myapp";
        WebApplicationContext webApplicationContext = createRootApplicationContext(servletContext);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
        servletContext.addServlet("dispatcher", new DispatcherServlet(webApplicationContext)).addMapping(contextPath + "/*");
    }

    private WebApplicationContext createRootApplicationContext(javax.servlet.ServletContext servletContext) {
        AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
        context.setServletContext(servletContext);
        // 配置其他的Bean和组件
        return context;
    }

}

这样配置之后,应用的URL将以/myapp开头。

SpringBoot 静态资源地址配置与访问路径 在开发基于 Spring Boot 框架的应用程序时,经常需要处理静态资源文件(例如 CSS、JavaScript 和图像文件等)。本教程将详细介绍如何配置静态资源地址并定义访问路径。希望本教程对你理解 Spring Boot 静态资源地址配置和访问路径有所帮助!如果我们希望将静态资源路径修改为其他路径,可以在。SpringBoot 静态资源地址配置与访问路径。通过以上配置,我们可以将静态资源路径修改为。例如,假设我们有一个 CSS 文件。可以直接访问这些静态资源文件。文件中进行相应的配置。 阅读详情

相关推荐

SpringBoot项目修改访问端口和访问路径的方法

创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/此时,我们就可以访问Controller层的接口了,如:http://localhost:8080/hello。

Sapphire521的博客 1091

Springboot项目访问路径

springboot项目的访问路径查询 创建的springboot项目,启动后,默认的访问路径是主机ip+默认的端口号是8080。如果没有配置默认的index.jsp,则访问显示Whitelabel Error Page。 如果在controller接口用requestMapping配置了请求路径,那么访问路径就是主机+默认端口号+方法的请求路径。如果在controller类上方定义了requestMapping,那么就是主机地址+默认端口号+类上的地址+方法地址去具体访问。 如果修改了端口,则访问路径是i

segegefe的博客 1万+

Easymesh之拓扑模块(二)

介绍 easymesh 拓扑消息:Topo discovery、Topo notification、Topo query、Topo response

qq_53619687的博客 2174

springboot 配置项目访问路径

在使用springboot时,在application.properties中配置了server.context-path=/test,如图: 启动项目: 发现端口生效为8084 ,而context path为空 检查springboot版本为2.2.4,SpringBoot在2.0版本之后已经弃用server.context-path,而代替为server.servlet.context-path 所以更换配置: server.servlet.context-path=/test 1 .

Be a Man Keep fighting for destination 9633

鸿蒙OpenHarmony技术:【Docker编译环境】

OpenHarmony为开发者提供了两种Docker环境,以帮助开发者快速完成复杂的开发环境准备工作。独立Docker环境:适用于直接基于Ubuntu、Windows操作系统平台进行版本编译的场景。基于HPM的Docker环境:适用于使用HPM工具进行发行版编译的场景。点击或者复制转到。表1Docker镜像介绍系统类型运行平台Docker镜像仓库标签标准系统(独立Docker环境)3.2小型系统(独立Docker环境)3.2轻量系统(独立Docker环境)3.2。

m0_62167422的博客 1450

技术前沿:半导体前道检测和量测设备修复技术

半导体前道检测设备是目前除光刻机外,国产渗透率较低的环节之一,近年来我国初步实现国产突破。前道检测相对后道检测环节壁垒更高,国内多家涉及后道测试,涉及前道检测和中道检测相对较少。

VOMMA的博客 4565

Springboot 配置项目 端口号 和 项目根 路径

Springboot 项目默认端口是8080,可以在启动的时候从打印日志中查看: 因此,创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/ 如果想使用其他端口, 需要进行额外配置: 方式一 修改配置文件 配置文件有两种,一种是application.properties, 一种为application.yml。 使用properties文件方式: 修改src目录下main目录下resources目录下的appli.

Ximerr的博客 2万+

C#实战:5分钟搞定Modbus RTU通讯(基于NModbus4库)

本文详细介绍了如何使用C#和NModbus4库快速实现Modbus RTU通讯,包括环境配置、核心功能实现、性能优化及常见问题排查。通过代码示例和实用技巧,帮助开发者高效完成工业自动化设备的数据采集与控制任务。

weixin_30689307的博客 476

SpringBoot上传文件到本地 配置项目访问路径URL的根路径,访问项目本地图片

SpringBoot配置项目访问路径URL的根路径,并访问项目本地图片

m0_46598549的博客 2819

UE5接入在线直播视频源,如hls(m3u8)格式

UE5接入在线直播视频源

专注GIS开发 9528

6、Dialogflow 开发全解析:从基础到高级应用

本文全面解析了 Dialogflow 的核心功能与高级应用,涵盖意图与实体的创建、上下文管理、后续意图设置以及高级实体类型的实际应用场景。详细介绍了自定义实体的导入导出规则、编程添加方法及数量限制,并通过流程图和实例说明了上下文生命周期与对话连贯性设计。结合电商、旅游、问卷调查等实际业务场景,展示了模糊匹配、自动扩展、复合实体等功能的强大灵活性。最后提供了开发最佳实践建议,帮助开发者构建高效、智能的对话系统。

kafka6courier的博客 110

SpringBoot将文件上传到项目的根路径中,相对路径

1.依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency&gt...

LuckFairyLuckBaby的博客 2万+

RK3568平台开发系列讲解:Linux wifi的调试

查询结果中state为ENABLE,表示hostapd程序启用成功。首先查看设备是否存在。

内核笔记 179

Linux:tomcat部署war包,项目使用根路径访问

1.安装Tomcat Linux确定已安装JDK,java -version检验; 下载tomcat linux的包,地址:http://tomcat.apache.org/download-80.cgi,选择tar.gz类型; 加压压缩包,tar -zxv -f apache-tomcat-8.5.38.tar.gz 启动Tomcat:进入apache-tomcat-8.5.38/bin...

xerjava的专栏 5591

KRC文件——编程中的重要文件

KRC文件是指KUKA机器人控制器(KUKA Robot Controller)所使用的文件格式。KUKA是一家知名的机器人制造商,其机器人控制器通过KRC文件来管理和执行机器人程序。KRC文件包含了机器人的运动指令、逻辑控制、传感器数据等信息,以及与机器人相关的配置参数。这些文件通常使用KRL(KUKA Robot Language)编写,是一种特定的编程语言。KRC文件具有扩展名为.krc的格式,可以在KUKA机器人控制器上直接加载和执行。

TechProX的博客 2977

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

SpringBoot 配置项目根路径

SpringBoot配置项目根路径

记录工作开发中遇到的技术难点,方便自己查看,也希望可以帮助到他人... 2121

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot配置图片访问动态路径

配置SpringBoot部署图片访问路径 网上大概是基于tomcat server更改的配置感觉很麻烦,所以写了个拦截器动态访问图片。 package com.kero99.filter; import java.io.File; import org.springframework.context.annotation.Configuration; import org.springf...

大道至简,悟在天成。 9264

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Linux环境下Springboot项目配置文件访问路径

在项目开发中总会需要访问服务器上的文件,如果是Tomcat项目,就可以直接在Tomcat中配置虚拟路径,接下来就看看如何在springboot项目中配置虚拟路径。 如下的config类中设置一个资源访问路径(upload),映射到本地件。 @Configuration public class WebConfig extends WebMvcConfigurationSupport { ...

qq_22656569的博客 4326

SpringBoot Web项目实例,配置访问路径与端口

背景 本篇演示以下几点: 如何配置一个SpringBoot Web项目 如何使用注解提供web接口 如何使用配置文件配置端口与访问路径 创建项目并导入 还是使用Spring Initializr创建一个项目,然后导入eclipse,项目信息如下: 配置SpringBoot Web项目 非常简单啊,只需要添加一个依赖即可: <dependency> <groupI...

编程副队长 5350

SpringBoot项目修改访问端口和访问路径

创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/ 此时,我们就可以访问Controller层的接口了,如:http://localhost:8080/hello package com.springboot.test; import org.springframework.web.bind.annotati...

刘鹏博的博客 14万+

SpringBoot配置项目访问路径URL的根路径

1、SpringBoot在2.0之前版本使用server.context-path server.context-path=/api 2、SpringBoot在2.0之后版本使用server.servlet.context-path server.servlet.context-path=/api

春风化雨 1万+
上一篇: 【知识点】js中的 json转换
下一篇: 【知识点】linux查看日志文件
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值