Spring Boot可以轻松创建Spring驱动的生产级应用程序和服务,并且可以轻松实现。它采用了Spring平台的观点,以便新用户和现有用户可以快速获得他们需要的位。
为什么ofertizerequests()允许访问未提及的端点,而不是? 我一直在试图将申请迁移到Springboot 3,并面临有关使用不推荐使用的授权Quests()与推荐的授权授权的问题(
与推荐的authorizeHttpRequests(<Customizer>)方法的问题。 以前我的配置与此相似: fun filterChain(http:Security): SecurityFilterChain { http.anonymous() .disable() .authorizeRequests() .antMatchers("/somePath1/**").hasRole("A") .antMatchers("/somePath2/**").hasRole("B") .antMatchers("/somePath3/**").hasRole("C") return http.build() } 这是按预期工作的,可以访问各自角色的路径。当我尝试访问其他路径"/somePath5/**"时,它不需要任何授权/身份验证。这是我的意图行为。所有访问都是内部的,因此无视此处的任何安全问题。 现在我试图使用推荐的authorizeHttpRequests(<Customizer>)复制这种行为。我正在尝试以下代码:fun filterChain(http:Security): SecurityFilterChain { http.anonymous{ it.disable() } .authorizeHttpRequests { it.requestMatchers("/somePath1/**").hasRole("A") .requestMatchers("/somePath2/**").hasRole("B") .requestMatchers("/somePath3/**").hasRole("C") .anyRequest().permitAll() } return http.build() 我不得不在此处添加最终权限。没有这个,我将无法访问.anyRequest().permitAll()以前,而被禁止403。 我想知道的是,为什么在使用"/somePath5/**"时我需要额外的行?我缺少两种方法之间有不同的东西吗? 我可以谷歌搜索最多的,这是在其他帖子中。但是当我遵循链接时,我找不到任何细节,如果它在那里,我将无法理解。 Edit:在此迁移期间,我从春季安全性5.7.3搬到6.1.0 贝洛代码也对我不起作用。 authorizeHttpRequests(<Customizer>)
yyes,通过Spring Data应用程序的Spring Boot的不同数据库中的实体之间的关联很具有挑战性,因为JPA并未本地支持交叉数据库关系。我们可以通过两种方式解决这个问题:
我正在做我的第一个春季项目,我在这里初始化表: 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>3.4.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.test</groupId> <artifactId>testcodechallenge</artifactId> <version>0.0.1-SNAPSHOT</version> <name>testcodechallenge</name> <description>Demo project for Spring Boot</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>17</java.version> <spring-boot.version>3.1.5</spring-boot.version> <lombok.version>1.18.30</lombok.version> <springdoc.version>2.2.0</springdoc.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>javax.persistence-api</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </path> </annotationProcessorPaths> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project> application.properties: spring.application.name=testcodechallenge spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.sql.init.mode=always spring.h2.console.enabled=true spring.h2.console.path=/h2-console schema.sql: DROP TABLE IF EXISTS PRICES; CREATE TABLE PRICES ( ID BIGINT AUTO_INCREMENT PRIMARY KEY, BRAND_ID INT NOT NULL, START_DATE TIMESTAMP NOT NULL, END_DATE TIMESTAMP NOT NULL, PRICE_LIST INT NOT NULL, PRODUCT_ID INT NOT NULL, PRIORITY INT NOT NULL, PRICE DECIMAL(10,2) NOT NULL, CURR VARCHAR(3) NOT NULL ); data.sql: INSERT INTO PRICES (BRAND_ID, START_DATE, END_DATE, PRICE_LIST, PRODUCT_ID, PRIORITY, PRICE, CURR) VALUES (1, '2020-06-14 00:00:00', '2020-12-31 23:59:59', 1, 35455, 0, 35.50, 'EUR'), (1, '2020-06-14 15:00:00', '2020-06-14 18:30:00', 2, 35455, 1, 25.45, 'EUR'), (1, '2020-06-15 00:00:00', '2020-06-15 11:00:00', 3, 35455, 1, 30.50, 'EUR'), (1, '2020-06-15 16:00:00', '2020-12-31 23:59:59', 4, 35455, 1, 38.95, 'EUR'); TestcodechallengeApplication.java: package com.test.testcodechallenge; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class TestcodechallengeApplication { public static void main(String[] args) { SpringApplication.run(TestcodechallengeApplication.class, args); } } 到目前为止很好:如果我跑步./mvnw spring-boot:run,然后访问http://localhost:8080/h2-consoleSELECT * FROM PRICES做一个4行。 ,但是,如果我有JPA存储库,则以上查询返回空: PriceController.java: package com.inditex.inditexcodechallenge.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import com.inditex.inditexcodechallenge.entity.Price; import com.inditex.inditexcodechallenge.service.PriceService; @RestController public class PriceController { @Autowired private PriceService priceService; @GetMapping("/prices") public List<Price> getAllPrices() { return priceService.getAllPrices(); } @GetMapping("/prices/{id}") public Price getPriceById(@PathVariable Long id) { return priceService.getPriceById(id); } } Price.java:package com.inditex.inditexcodechallenge.entity; import java.math.BigDecimal; import java.time.LocalDateTime; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import lombok.Data; @Data @Entity @Table(name = "PRICES") public class Price { @Id private Long id; private Long brandId; private LocalDateTime startDate; private LocalDateTime endDate; private Long priceList; private Long productId; private BigDecimal price; private String currency; } PriceRepository.java:package com.inditex.inditexcodechallenge.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import com.inditex.inditexcodechallenge.entity.Price; @Repository public interface PriceRepository extends JpaRepository<Price, Long> { // Custom query methods can be added here if needed } PriceService.java:package com.inditex.inditexcodechallenge.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.inditex.inditexcodechallenge.entity.Price; import com.inditex.inditexcodechallenge.repository.PriceRepository; @Service public class PriceService { @Autowired private PriceRepository priceRepository; public List<Price> getAllPrices() { return priceRepository.findAll(); } public Price getPriceById(Long id) { return priceRepository.findById(id).orElse(null); } } 当您尝试获取数据时,您可以发布通过Hibernate构建的查询吗?我认为识别这个问题会更容易。谢谢
在整个项目中都有一个名为
array_overlaps()
SpringBoot 3 OAuth2 GitHub登录:电子邮件属性即使在设置范围和公共电子邮件
我尝试了什么 配置application.yml具有正确的范围:
带Java 21虚拟线程的弹簧启动 - 有没有办法优雅地终止?
INSB 3.4 + JAVA 21,当您终止Java进程时,无论任务执行程序类型如何,它都会等到所有线程完成,其中包括计划的作业以及API调用。 但是,...
从我的Spring Boot应用程序中,我尝试使用Plain SQL使用JOOQ 3.2.5(免费版)调用DB2 UDF: @Autowired 私有DSLContext上下文; @Override public list查找(int inde ...
即使我在实体类中和spring.data.mongodb.auto-index-creation = true中有@index的注释。
sissue:无法在Exchange SBA中阅读请求或有效载荷 我面临一个问题,即我无法在交易所内阅读请求或有效载荷,这显然是由于反应堆堆栈中的基础。不幸...