spring 相关问题

Spring Framework是Java平台上应用程序开发的开源框架。其核心是对基于组件的体系结构的丰富支持,目前它拥有20多个高度集成的模块。

@ResponseStatus Spring 注解对于 RESTful 应用程序到底如何工作?

我正在学习Spring Core认证,我对Spring如何处理REST请求有一些疑问。 我知道通过 REST,资源会以名称的形式公开,并且对这些资源的操作

回答 1 投票 0

如何在Jhipster 8.4.0(account.model)中获取用户Id不在类中显示id但在控制台中显示

我在我的角度项目中使用 Jhipster 8.4.0 我无法获取登录帐户的用户的 ID,无法使用该 ID 进行搜索。 使用: ngOnInit() { this.primengConfig.ripple = true; 这个。

回答 1 投票 0

Spring 控制器测试随机失败

有一个项目大约有20个控制器。每个控制器都有其对应的测试类。 当我们尝试添加新的控制器测试类时,之前正在运行的一些测试

回答 1 投票 0

为什么Spring中找不到JSP?文件存在

在一个非常基本的应用程序中,我有 sayHelloController.java 如下 @控制器 公共类 SayHelloController { @RequestMapping(“说你好-jsp”) 公共字符串 sayHelloJsp() { ...

回答 3 投票 0

我可以将不同的 Spring 5.x 版本升级到单个 6.x 版本吗?

我想将 Wildfly 28 的 spring 版本升级到 6.1.0,但我在应用程序 pom.xml 中发现,我看到不同版本的 spring 相关 jar(例如 5.3.20、5.2.2、2.3.2)。 ....),如下所示...

回答 1 投票 0

使用 MockMvc 测试发送带有文件的对象

我想将一个对象发送到控制器,该对象具有多个包含文件的列表和多个包含纯文本的字段。 公共类贡献新 { 私人名单 我想将一个对象发送到控制器,该对象具有多个包含文件的列表和多个包含纯文本的字段。 public class ContributionNew<T extends MovieInfoDTO> { private List<T> elementsToAdd; private Map<Long, T> elementsToUpdate; private Set<Long> idsToDelete; private Set<String> sources; private String comment; } public class Photo extends MovieInfoDTO { private MultipartFile photo; } @PostMapping(value = "/{id}/contributions/photos") @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createPhotoContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Photo> contribution ) { 我想创建一个测试来发送对象,但我不知道如何完成它。 @Test public void testCreatePhotoContribution() throws Exception { ContributionNew<Photo> contribution = new ContributionNew<>(); MockMultipartFile multipartFile = new MockMultipartFile("photo", "C:\\Users\\Jonatan\\Pictures\\2.png", "image/png", "Spring Framework".getBytes()); Photo.Builder photoBuilder = new Photo.Builder( multipartFile ); contribution.getElementsToAdd().add(photoBuilder.build()); mockMvc .perform(post("/api/v1.0/movies/{id}/contributions/photos", 1) .contentType(...) .content(...)) .andExpect(status().isCreated()); } 我不知道如何为传输的数据设置正确的类型,设置内容。仅有关仅发送文件(不在对象中)的教程可用。但没有指南表明文件是对象中的字段之一。怎么办? 对于那些想知道的人: 您可以发送 MultipartFile 和一些纯文本字段,以映射到控制器中的 1 个对象。看看我的例子。 达: public class NewFileInfoDto { @NotNull @Positive() private Long requestId; @NotNull private MultipartFile file; } 控制器: @PostMapping @ResponseStatus(HttpStatus.CREATED) public FileInfoDto addFile(@ModelAttribute @Valid NewFileInfoDto dto) { return fileService.addFile(dto); } 测试部分: mockMvc.perform(multipart("/file") .file(file) .param("requestId", "3") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()); ```

回答 1 投票 0

如何从数据库获取图像到itext7中的< Image>?

在我的invoiceGenerator中,我需要获取发票中的图像,该图像作为字节[]存储在postgres数据库中 因为我将此图像输入从方法中硬编码的本地路径更改为实体 ImageDa...

回答 1 投票 0

使用 Spring Boot 运行测试时未注册 GraphQL 服务

我有一个应用程序,其中包含 Camel (3.14) 和 GraphQL (starter, 0.0.6)。应用程序构建在 Spring Boot (2.7.5) 之上。 应用程序工作正常,但运行测试时如下: @CamelSpringBootTest @

回答 1 投票 0

Java 无法使用 Spring Boot 构建 .jar

我尝试使用 Spring Boot for Java8 构建 .jar。 但是,我收到这个消息。 应用插件请求时发生异常 [id: 'org.springframework.boot', version: '1.5.21.RELEASE'] 无法应用 plu...

回答 1 投票 0

在抽象类方法上不执行任何操作,但在从concreate类实例调用时应该可以工作

我有以下结构: 类样本{ 私人地图服务地图; @Autowired 私人列表服务; @PostConstruct 公共无效初始化{ this.serviceMap = this.servi...

回答 1 投票 0

如何在不构建项目中所有单元和合约测试的情况下生成并运行单个合约测试? Java Spring Cloud 合约验证器

我是合同测试新手。要运行测试,我使用 maven 命令 mvn clean test。它运行我项目中的所有测试,Spring Cloud生成合约测试类,整个过程需要很多时间......

回答 2 投票 0

Spring Shell 未初始化

我正在尝试创建一个 CLI 应用程序,该应用程序具有使用 Spring Shell 的多个命令,并且依赖于另一个项目和 Spring。这是我的 pom: es.uca.dss.sigeca 我正在尝试创建一个 CLI 应用程序,该应用程序具有多个使用 Spring Shell 的命令,并且依赖于另一个项目和 Spring。这是我的pom: <groupId>es.uca.dss.sigeca</groupId> <artifactId>cli</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>es.uca.dss.sigeca</groupId> <artifactId>core</artifactId> <version>0.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>3.0.6</version> </dependency> <dependency> <groupId>org.springframework.shell</groupId> <artifactId>spring-shell-starter</artifactId> <version>2.1.5</version> </dependency> </dependencies> <build> <plugins> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <artifactId>maven-jar-plugin</artifactId> <version>3.1.2</version> <configuration> <archive> <manifest> <mainClass>es.uca.dss.sigeca.Main</mainClass> </manifest> </archive> </configuration> </plugin> <!-- Add the assemble plugin with standard configuration --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <archive> <manifest> <mainClass>es.uca.dss.sigeca.Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> Main.java如下: package es.uca.dss.sigeca; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Main { public static void main( String[] args ) { SpringApplication.run(Main.class, args); } } 我的命令: package es.uca.dss.sigeca; import org.springframework.shell.standard.ShellMethod; import java.util.Date; import org.springframework.shell.standard.ShellComponent; @ShellComponent public class MyCommands { IServicesClient servicesClient = ServicesProvider.getClientServices(); IServicesVehicle servicesVehicle = ServicesProvider.getVehicleServices(); IServicesReserve servicesReserve = ServicesProvider.getReserveServices(); @ShellMethod("Consults if a car is avalaible between two determined dates.") public void consultDisponibility(String enrollment, Date start, Date end) { if(servicesReserve.isAvailable(servicesVehicle.getVehicle(enrollment), start, end)) { System.out.println("It is avalaible.\n"); } else System.out.println("It is not avalaible.\n"); } @ShellMethod("Register a new client.") public void clientRegister(String ID, String contact, String name) { servicesClient.registerClient(ID, contact, name); } @ShellMethod("Edit data from a client.") public void clientEdit(String ID, String contact, int incidences) { servicesClient.editClient(ID, contact, incidences); } } 与其他项目的依赖关系似乎很好,因为 .jar 生成的文件包含它们,并且我没有编译问题。 我尝试使用 mvn clean install -DskipTests 然后 java -jar target/cli1.0-jar-with-dependency.jar 和 spring 缩写来执行它,但是没有 Spring Shell 输出或提示发出命令,它刚刚完成执行。 这是输出: java -jar target/cli-1.0-jar-with-dependencies.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.0.6) 15:31:09.186 [main] INFO es.uca.dss.sigeca.Main -- Starting Main using Java 17.0.7 with PID 39497 (/home/alex/Documentos/DSS/dss2022-2023-SiGeCa/cli/target/cli-1.0-jar-with-dependencies.jar started by alex in /home/alex/Documentos/DSS/dss2022-2023-SiGeCa/cli) 15:31:09.190 [main] DEBUG es.uca.dss.sigeca.Main -- Running with Spring Boot, Spring 15:31:09.192 [main] INFO es.uca.dss.sigeca.Main -- No active profile set, falling back to 1 default profile: "default" 15:31:09.194 [main] DEBUG org.springframework.boot.SpringApplication -- Loading source class es.uca.dss.sigeca.Main 15:31:09.309 [main] DEBUG /* A lot of mor DEBUGs... */ 'org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration' 15:31:11.105 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory -- Creating shared instance of singleton bean 'spring.sql.init-org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties' 15:31:11.143 [main] INFO es.uca.dss.sigeca.Main -- Started Main in 2.279 seconds (process running for 2.6) 15:31:11.146 [SpringApplicationShutdownHook] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext -- Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@2b4a2ec7, started on Tue Apr 25 15:31:09 CEST 2023 我希望任何人都可以帮助我,我已经解决这个问题很长时间了。 不幸的是,我没有回答你的问题,因为我也有同样的问题。 我能看到的唯一区别是: <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.shell</groupId> <artifactId>spring-shell-dependencies</artifactId> <version>${spring-shell.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> 但我不认为会改变什么

回答 1 投票 0

AWS IAM 和 spring-session-data-redis 的集成

有一个使用 spring-session-data-redis 的 Spring Boot 项目。 在本地,一切都是开箱即用的。 (本地主机:6397) 在“上”阶段,我们使用 AWS 中的 Redis 和一个 Configu...

回答 1 投票 0

Hibernate 不会在父对象中加载子对象

我正在尝试制作一个简单的程序来构建工作时间表,但无法正确获取数据。当我试图招募员工时 @实体 @数据 @Builder @AllArgsConstructor @NoArgs构造函数 公开课

回答 1 投票 0

将 jakarta 10 wildfly 28 的 spring 升级到版本 6.1.7

我想将 Wildfly 28 的 spring 版本升级到 6.1.0,但我在应用程序 pom.xml 中发现,我看到不同版本的 spring 相关 jar(例如 5.3.20、5.2.2、2.3.2)。 ....),如下所示...

回答 1 投票 0

我在应用程序中的 pom.xml 上运行测试时遇到问题,它显示 org.springframework.boot:spring-boot-starter-test:jar:${spring.boot.version}

我的 pom.xml 文件中不断出现这 2 个错误 1 是:缺少工件 org.springframework.boot:spring-boot-starter-test:jar:${spring.boot.version} 第二个是:插件“org”的版本解析错误。

回答 1 投票 0

带有 Tomcat 的 Spring MVC 仅渲染index.jsp

问题是,当我使用 Tomcat 运行我的应用程序时,它在浏览器中仅显示 index.jsp。但控制器不起作用。 这是我的 web.xml 文件: 问题是,当我使用 Tomcat 运行我的应用程序时,它在浏览器中仅显示 index.jsp。但控制器不起作用。 这是我的web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>spring-course-mvc</display-name> <absolute-ordering /> <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/applicationContext.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> applicationContext.xml 文件: <?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" xmlns:mvc="http://www.springframework.org/schema/mvc" 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.myapp.spring.mvc" /> <mvc:annotation-driven/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean> </beans> 我的控制器: package com.myapp.spring.mvc; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MyController { @RequestMapping("/") public String showFirstView() { return "first-view"; } } 我的 view 所在的 webapp/WEB-INF/ 中有 first-view.jsp 目录。所以看起来webapp/WEB-INF/view/first-view.jsp 当我在 http://localhost:8080/spring_course_mvc/ 上运行项目时,出现 404 错误。 有趣的是,当我添加 webapp/index.jsp 文件时,我在 http://localhost:8080/spring_course_mvc/ 上看到其内容。 然后我添加了 webapp/first-view.jsp 文件和地址 http://localhost:8080/spring_course_mvc/first-view.jsp 它正在工作。 没有 webapp/index.jsp 地址 http://localhost:8080/spring_course_mvc/ 会给我 404 错误。 首先,您需要确保如果您使用的是Spring 5,则需要使用Tomcat 9。 如果您使用的是 Spring 6,则需要使用 Tomcat 10。 接下来您需要确保您的 web.xml 和 applicationContext.xml 位于 webapp/WEB-INF/web.xml 和 webapp/WEB-INF/applicationContext.xml。 您需要记住的另一件事是,如果您的应用程序不会自动运行浏览器,您需要确保使用正确的上下文根值。在 Eclipse 中,您可以通过右键单击项目 > 属性 > Web 项目设置来检查。

回答 1 投票 0

我应该如何组织我的 Spring Boot 文件结构?

我正在创建一个电影评论应用程序,到目前为止我创建了我的应用程序的数据库架构。 电影应用架构 我不确定应该如何组织我的项目结构。如果我有一个典型的逐层封装,那么我...

回答 1 投票 0

在 Spring 中的 servlet 过滤器内启用 Hibernate 过滤器

我正在开发一个多租户应用程序,这意味着我需要能够根据拥有请求用户配置文件的组织帐户来过滤 API 响应。在我们的模型中,这是参考...

回答 1 投票 0

Sublime Text 3、rbenv、rspec、spring 和 ruby 测试

我正在 Sublime Text 3 中使用优秀的插件 sublime-text-2-ruby-tests 并使其正常工作。但测试速度相对较慢(单次测试约 5-6 秒,完整测试约 10 秒

回答 1 投票 0

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