spring-test-mvc 相关问题


在 Spring-MVC 中显示 JSP 页面时出现问题

我在 Spring-MVC 中显示 jsp 页面时遇到问题。 这是带有 Gradle 和 IntelliJ CE 的基本 hello world Spring-MVC: 我收到以下错误页面: 这是我的 build.gradle: 构建脚本{


我想将商品添加到购物车中。有没有 spring-mvc 的示例

我想将商品添加到购物车中。我想用 spring-mvc 编写。 在购物车中,我想添加商品的名称和价格。如果我按每个商品的“添加到购物车”按钮,它必须进入购物车并显示名称和价格...


如何在spring-boot web客户端发送请求体?

我在 Spring Boot Web 客户端发送请求正文时遇到一些问题。尝试发送如下所示的正文: val 主体 = "{ ” + "\"电子邮件\":\"[email protected]\", ” + “\”id\“:...


Spring Cloud Gateway 返回 404 未找到错误

我尝试使用 Reactive 和 MVC Spring Cloud API 网关,但在两次尝试中我都在 Postman 中收到 404 Not Found 错误响应。 我只有一个用户服务和一个发现服务器(尤里卡)...


Spring MVC中BindingResult接口有什么用?

BindingResult 对于仅将异常与视图绑定还是其他有用? BindingResult的具体用途是什么? 或者它在将模型属性与视图绑定时有用吗?


从Mysql中检索Blob并在JSP上显示它

如何将blob形式的mySQL转换并在jsp上显示? 在 DAO 中写完这个之后我不知道如何继续。 我最近才了解简单的spring mvc。 公开名单


Nginx 安全链接和 java

我有一个项目,我需要从我的服务器流式传输视频,我使用 nginx 来完成它,还使用 spring mvc 开发的 webapp 和 tomcat 来包含它。 怎么运行的: java应用程序制作md5哈希...


Spring boot + slf4j + log4j + 类 org.apache.logging.slf4j.SLF4JLoggerContext 无法转换为类

我有Spring boot 2.3.1 pom.xml 我有Spring boot 2.3.1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>logger</groupId> <artifactId>logger</artifactId> <version>0.0.1-SNAPSHOT</version> <name>logger</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> <lombok.version>1.18.12</lombok.version> <log4j.version>1.2.17</log4j.version> <slf4j.version>1.7.30</slf4j.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <artifactId>logback-classic</artifactId> <groupId>ch.qos.logback</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 班级 @Slf4j @SpringBootApplication public class LoggerApplication { public static void main(String[] args) { log.info("++++++++++++++++++++++++TEST+++++++++++++++++++++++++++++"); SpringApplication.run(LoggerApplication.class, args); } } 应用程序.属性 logging.config=classpath:log4j.properties log4j.properties log4j.rootLogger=INFO, console log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.Target=System.out log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n 我尝试寻找解决方案,查看论坛上的类似主题,尝试各种排除依赖项的选项。 线程“main”中的异常 java.lang.ClassCastException:类 org.apache.logging.slf4j.SLF4JLoggerContext 无法转换为类 org.apache.logging.log4j.core.LoggerContext (org.apache.logging.slf4j.SLF4JLoggerContext 和 org.apache.logging.log4j.core.LoggerContext 位于未命名模块中 加载器“应用程序”)位于 我还尝试排除一些依赖项 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <artifactId>logback-classic</artifactId> <groupId>ch.qos.logback</groupId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> 但又出现错误,但现在无法再格式化日志了。 2021-01-13 19:12:15,881 信息 - ++++++++++++++++++++++++测试+++++++++++++++++++++++++++++++ 错误 StatusLogger 无法识别的格式说明符 [d] 错误 StatusLogger 无法识别的转换说明符 [d] 从转换模式中的位置 16 开始。 错误 StatusLogger 无法识别的格式说明符 [线程] 错误 StatusLogger 无法识别的转换说明符 [线程] 从转换模式中的位置 25 开始。 错误 StatusLogger 无法识别的格式说明符 [级别] 错误 StatusLogger 无法识别的转换说明符 [level] 从转换模式中的位置 35 开始。 ... 错误 StatusLogger 无法识别的格式说明符 [n] 错误 StatusLogger 无法识别的转换说明符 [n] 从转换模式中的位置 56 开始。 警告:不支持 sun.reflect.Reflection.getCallerClass。这会影响性能。 任何人都可以有任何想法如何解决它吗? 我找到了解决这个问题的方法。事实证明,问题出在其中一个私有库(elastik 的附加程序)的冲突上。 我执行了命令: mvn dependency:tree 然后找到传递依赖项,并将它们排除在所有类的路径上,以排除日志记录所需的库冲突。 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <artifactId>logback-classic</artifactId> <groupId>ch.qos.logback</groupId> </exclusion> <exclusion> <artifactId>log4j-to-slf4j</artifactId> <groupId>org.apache.logging.log4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <artifactId>springfox-boot-starter</artifactId> <groupId>io.springfox</groupId> <version>3.0.0</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${version.log4j.core}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency>


如何在 ASP.NET MVC 4 中为 CSP 使用动态随机数

我在 ASP.NET MVC 4 中开发了 MVC 应用程序。我在几个页面中使用了 javascript。一些 javascript 被引用为 @Scripts.Render(“~/Scripts/bootstrap”) @Scripts.Render("~/Sc...


如何使用 .NET TEST EXPLORER 在 VS Code 中运行 NUnit 测试

我想从 .NET TEST EXPLORER 运行单元测试,而不是命令行。我可以在导航到单元测试目录并执行 dotnet test 时运行测试。 但选择 .NET TEST EXPLORER...


闪亮的server.R无法读取全局变量

./app 中的两个文件 ui.R 图书馆(闪亮) 一个<- 1 ui <- fluidPage( textOutput("test") ) server.R server <- function(input, output) { output$test <- renderText({ a ...


php 使用函数更改函数外部变量的值

我试图在使用函数时更改函数外部声明的变量的值 我试图更改在使用函数时声明的变量的值 <?php $test = 1; function addtest() { $test = $test + 1; } addtest(); echo $test; ?> 但似乎不能。只有在函数中声明为参数的变量才有效。有这方面的技术吗?预先感谢 将函数内部的变量更改为全局变量 - function addtest() { global $test; $test = $test + 1; } 使用全局变量有很多注意事项 - 从长远来看,您的代码将更难维护,因为全局变量可能会对未来的计算产生不良影响,您可能不知道如何操纵变量。 如果重构代码并且函数消失,这将是有害的,因为 $test 的每个实例都与代码紧密耦合。 这里有一个轻微的改进,不需要 global - $test = 1; function addtest($variable) { $newValue = $variable + 1; return $newValue; } echo $test; // 1 $foo = addtest($test); echo $foo; // 2 现在您不必使用全局变量,并且可以根据自己的喜好操作 $test,同时将新值分配给另一个变量。 不确定这是否是一个人为的示例,但在这种情况下(与大多数情况一样),使用global将是极其糟糕的形式。为什么不直接返回结果并分配返回值呢? $test = 1; function increment($val) { return $val + 1; } $test = increment($test); echo $test; 这样,如果您需要增加除 $test 之外的 任何其他 变量,您就已经完成了。 如果您需要更改多个值并返回它们,您可以返回一个数组并使用 PHP 的 list 轻松提取内容: function incrementMany($val1, $val2) { return array( $val1 + 1, $val2 + 1); } $test1 = 1; $test2 = 2; list($test1, $test2) = incrementMany($test1, $test2); echo $test1 . ', ' . $test2; 您还可以使用 func_get_args 接受动态数量的参数并返回动态数量的结果。 使用 global 关键字。 <?php $test = 1; function addtest() { global $test; $test = $test + 1; } addtest(); echo $test; // 2 ?> 也许你可以试试这个。 <?php function addTest(&$val){ # Add this & and val will update var who call in from outside $val += 1 ; } $test = 1; addTest($test); echo $test; // 2 $anyVar = 5; addTest($anyVar); echo $anyVar; // 6


ASP.NET MVC 中的自动刷新

在网络表单中我会这样做 函数 timedRefresh(timeoutPeriod) { setTimeout("location.reload(true);", timeoutPeriod); } ...


VS2017:为什么razor项目仍然引用MVC?

我对 ASP.NET Core 2.0 的 MVC 和 razor 项目非常困惑。 在 Visual Studio 2017 中我执行以下操作: 新项目 Web ASP.NET Core 应用程序 (C#) Web 应用程序(不是 Web 应用程序 MV...


为什么 Razor Pages 项目仍然引用/依赖 MVC?

我对 ASP.NET Core 2.0 的 MVC 和 Razor Pages 项目非常困惑。 在 Visual Studio 2017 中我执行以下操作: 新项目 Web ASP.NET Core 应用程序 (C#) 网络应用程序(不是网络应用程序...


为什么 Razor Pages 项目仍然引用/依赖 MVC?

我对 ASP.NET Core 2.0 的 MVC 和 Razor Pages 项目非常困惑。 在 Visual Studio 2017 中我执行以下操作: 新项目 Web ASP.NET Core 应用程序 (C#) 网络应用程序(不是网络应用程序...


ASP.NET Core 6 MVC:仅使用授权策略在 HttpPost 上出现 cors 错误

我已将 ASP.NET Core 6 MVC 应用程序添加到 Azure“应用程序注册”,并且我能够使用 Microsoft WebUI 登录并执行 GET 请求来获取例如我的观点。 应用...


将 Spring Security 5 迁移到 Spring Security 6 HttpSecurity 问题

Spring Security 6 中以下代码应该替代什么? http .authorizeRequests() .requestMatchers("/hub/**").access("hasPermission('SOME_LAYER', '')")...


Spring Boot 版本与 Java 11 兼容

大家好,目前我正计划将具有 spring 版本 4.0.6 和 java 8 的独立 spring 应用程序迁移到具有 java 11 的 Spring boot 应用程序。所以,继续使用 spring boot


指定psql连接的默认数据库?

在使用psql时,我想更改初始数据库连接。 我有一个名为“test”的数据库作为初始连接。 从命令行运行 psql 时,我的提示符为 test=# 之后


如何在 ASP.NET MVC 中将参数和数据从控制器发送到 SignalR hub?

我使用 ASP.NET MVC。我想将数据从控制器发送到集线器以发送给客户端。我在控制器中编写了这段代码: 公共类 SampleController :控制器 { 私人只读 IHubCo...


C# 和 ASP.NET Core MVC:选择 100 个图像时 IFormFileCollection 为 NULL

为什么在 C# 和 ASP.NET Core MVC 中回发到控制器操作时 IFormFileCollection 为 NULL? 如果我选择 10 张图像,它会起作用,如果我选择 100 张图像,它会失败 - 为什么?文件上传有限制吗...


ASP.NET MVC 多选下拉列表

我使用以下代码让用户选择表单上的多个位置。 @Html.DropDownListFor(m => m.location_code, Model.location_type, new { @class = "form-control", @multiple = "mul...


grpc-spring-boot-starter - 如果我将 spring-boot-starter-jdbc 添加到依赖项中,netty 服务器不会启动

我开始用spring boot测试grpc,我使用net.devh中提供的GrpcService:grpc-spring-boot-starter(https://yidongnan.github.io/grpc-spring-boot-起动器/en/)。 它隔离效果很好...


写入通道的随机结果(Go)

我有以下代码: 函数 writeToClosedBufferedChannel() { ch := make(chan int, 2) ch <- 10 ch <- 20 go func() { fmt.Println("test") ch <- ...


如何在Spring Boot 3和Spring Framework 6中注册拦截器

我正在使用 Spring Boot 3.1.0-SNAPSHOT 构建后端,它使用 Spring Framework 6x。 拦截器: @Slf4j 公共类 MyInterceptor 实现 HandlerInterceptor { @覆盖 公众嘘声...


当从 ASP.NET Core MVC 获取 api 到 Reactjs 时,是什么提示 get 方法返回 HTML 而不是它应该返回的 json 数据?

我正在尝试创建一个应用程序,其中客户端前端使用react.js 制作,后端使用ASP.Net Core MVC。我正在尝试从 api 获取数据以渲染


使用Pytest时将主数据库更改为Test

帮我解决问题 这是我的设置.py: 数据库= { “默认”: { "ENGINE": "django.db.backends.mysql", “名称”:ENV.MYSQL_DSN....


Jaxb2Marshaller 与 Spring boot 3+ 和 Jaxb 4 兼容吗?

我正在将我的项目从 Spring Boot 2.7 升级到 Spring Boot 3.1。在这个项目中仍然使用 SOAP,因此我们依赖 Jaxb 和 spring WS。 我正在使用 com.helger.maven 生成 Java 类:


Spring @Transactional 迁移到 Spring 5 后不起作用

我最近将应用程序从带有 AspectJ 1.8.10 的 Spring 4.3.x 和 JDK 8 升级到带有 Spring 5.3.x 和 AspectJ 1.9.20.1 的 JDK 17,并且事务注释似乎不起作用 在应用中...


bean“mvcHandlerMappingIntrospectorRequestTransformer”无法注册。具有该名称的 bean 已被定义并覆盖 i

环境:Spring Boot 3.2.1、JDK 21、GraalVM、Spring Native、Spring Security。错误 微软Windows [版本10.0.22631.2861] (c) 微软公司。版权所有。 。 ____ ...


Spring Boot api 在多次成功的 200 响应后给出 403

我有一个 Spring Boot 应用程序,它使用 spring security 作为依赖项。我正在将 Spring boot 版本从 2.7.16 迁移到 3.2.1。在 2.7.16 版本中一切正常。但在 3.2.1 中,其余 API 都...


如何在Spring 3.0中实现Scaffolding

“我正在使用 spring maven 项目,想要在其中实现脚手架,以便我可以根据模型动态生成 DAO、服务和 spring 表单。如何实现?”


来自有序字典的Python Json

我正在尝试创建一个嵌套的 Json 结构,如下所示: 示例 Json: { “id”:“德”, “密钥”:“1234567”, “来自”:“[email protected]”, “过期”:“2018-04-2...


需要演示 DataTypeAttribute 的这种用法(如 Microsoft 教程中所述)

我正在从 ASP.NET MVC 迁移到 ASP.NET Core,同时学习此页面上的 Microsoft 文档 https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages /验证?view=aspn...


如何使用xslt将xml中的文本转换为html中的超链接

如何使用 xslt 将 xml 中的文本转换为 html 中的超链接。 我的 Xml 代码是 C:\测试\CaptureF15165617TC001_05_06_1516_57_11.png 如何使用 xslt 将 xml 中的文本转换为 html 中的超链接。 我的Xml代码是 <Steps> <Filepath>C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</Filepath> </Steps> 将其转换为 html,我的 xslt 代码如下 <td width='15%'> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="./Filepath"/> </xsl:attribute> <xsl:value-of select="./Filepath"/> </xsl:element> </td> 现在这段代码在html中写入文件的整个路径,但我只想在html中写入“文件”以及指向文件位置的超链接。 我当前生成的html代码如下 C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png <td width="15%"><a href="C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png">C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</a></td> 我想要的是 <td width="15%"><a href="C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png">File</a></td> 任何人都可以帮助我需要在 xslt 中进行哪些更改。 你告诉它具有价值: <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="./Filepath"/> </xsl:attribute> <xsl:value-of select="./Filepath"/> <!--This is the link text --> </xsl:element> 所以将其更改为: <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="./Filepath"/> </xsl:attribute> File </xsl:element> 或者简短地说: <a href="{Filepath}">File</a> <Steps> <Filepath>C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</Filepath> </Steps>


Spring Boot 集成测试抛出错误“java.lang.IllegalStateException:阻塞读取超时 5000 毫秒”

问题发生在我通过 Spring boot 2.0.0.M3 使用 Spring webflux 的项目上。以下是项目的依赖项, 依赖项{ 编译 'org.springframework.boot:spring-boot-starter-


mod_rewrite到子目录中相应的php文件

我想使用 mod_rewrite (在 .htaccess 中)将“干净”的 URL 映射到子目录中相应的 php 文件,例如: https://example.com/test/ --> https://example.com/p/test.php 我的...


AWS sts 在一个命令中承担角色

要在 CLI 中承担 AWS 角色,我执行以下命令: aws sts 假设角色 --role-arn arn:aws:iam::123456789123:role/myAwesomeRole --role-session-name test --region eu-central-1 这给...


Iframe 外部 API 回调将 ASP.NET MVC 会话对象重置为 null

解释起来有点棘手,但我会尽力解释问题。首先,它仅在 Firefox、Chrome 和 Edge 上按预期运行。 我有一个网络退房表格...


ASP .net core MVC 中的 ViewModel

我试图从控制器调用我的视图模型,但它给我一个错误,SqlException:当它到达我的@foreach(模型中的var item)语句时,对象名称'OfficerLangVM'无效。我也不是太


ASP Fix/Int 函数未按预期运行

在调试时,我在自定义 RoundMid() 函数中发现了这个奇怪的事情: 测试 = 148.325 * 100 + 0.5 Response.Write 测试 ' 返回 14833 Response.Write Fix(test) ' 返回 14832 ??????...


HtmlHelpers Html.LabelFor/TextBoxFor/EditorFor 在 ASP.NET Core Razor 页面中无法识别

我有一个从 .NET Core 3.1 迁移的 .NET 5.0 MVC 项目,但使用 Html.LabelFor、Html.TextBoxFor 或 Html.EditorFor 的表单不显示输入。 看法: @模型更新产品视图模型; @{ 使用...


Visual studio 2017 发布陷入困境

我正在尝试部署我的 ASP.NET MVC 项目(到文件夹中),但是该过程卡在这里: 我认为,今天的发布流程已更新,因为昨天它有不同的界面...


React 应用程序如何连接到 OAuth 2 Spring 授权服务器/资源服务器/oauth 客户端后端

我已经实现了一个生成令牌的 OAuth 2 spring 授权服务器。端口4002 用于 api 调用的 spring 资源服务器。端口4003 一个 spring oauth 客户端,用于处理与


LINQ to Entities - MVC / C# 中仅支持无参数构造函数和初始值设定项

我正在将 Linq-to-Sql 应用程序更改为 EF 6.1,使用以下命令生成 ViewData: 公共 IEnumerable> GetOhaTypes () { 返回(来自数据库中的类型。


Spring Boot JSP 404.Whitelabel 错误页面

无法使用 spring-boot 加载非常简单的 JSP 页面,出现 404 Not Found HmisApplication.class @SpringBootApplication 公共类 HmisApplication 扩展 SpringBootServletInitializer { @覆盖


如何从.Net Core中的Content.ReadAsStringAsync方法获取字符串?

我正在尝试读取 WEB API 的响应,该响应返回字符串。 我使用下面的语句: response.Conent.ReadAsStringAsync().Result.ToString(); 我期待结果是“TEST”...


通过 Maven Spring Boot 插件运行应用程序时如何设置 Java Xmx 标志?

我正在使用 mvn spring-boot:run 运行应用程序。我正在尝试按照此处所述设置 Xmx 标志: mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xmx512m" 但它不...


ASP.NET Core MVC 从视图调用操作

我尝试创建一个电子商务网站。我有一个带有“添加到购物车”按钮的产品页面。在此页面(SingleProduct.cshtml)上,我还从客户处获取产品数量。这个...


© www.soinside.com 2019 - 2024. All rights reserved.