我的项目中有以下控制器端点:
@GetMapping(value = "/{id}")
public FooDto findOne(@PathVariable Long id) {
Foo model = fooService.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
return toDto(model);
}
Run Code Online (Sandbox Code Playgroud)
当我的应用程序找不到Foo具有提供的 id 的响应时,它检索到以下响应:
{
"timestamp": "2023-01-06T08:43:12.161+00:00",
"status": 404,
"error": "Not Found",
"path": "/foo/99"
}
Run Code Online (Sandbox Code Playgroud)
但是,升级到 Boot 3 后,响应正文更改为:
{
"type": "about:blank",
"title": "Not Found",
"status": 404,
"instance": "/foo/99"
}
Run Code Online (Sandbox Code Playgroud)
我在《Spring Boot 3.0 迁移指南》和《升级到 Spring Framework 6.x 》中都找不到任何相关信息。
自从迁移到 Spring Boot 3.0 以来,跟踪已停止与计划作业一起工作@Scheduled(fixedDelay = 69, timeUnit = TimeUnit.SECONDS)
根据迁移文档,我们应该使用ContextScheduledExecutorService.wrap() https://github.com/micrometer-metrics/tracing/wiki/Spring-Cloud-Sleuth-3.1-Migration-Guide#async-instrumentation包装执行程序服务
根据 spring 文档,我们应该能够这样做
@Configuration
@EnableScheduling
public class AppConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}
@Bean(destroyMethod="shutdown")
public Executor taskExecutor() {
return ContextScheduledExecutorService.wrap(Executors.newScheduledThreadPool(100));
}
}
Run Code Online (Sandbox Code Playgroud)
正在使用正确的调度程序,因为我在设置调度程序时可以看到自定义线程名称,但日志跟踪未显示(traceId、spanId)。否则,跟踪工作就像我在同一应用程序中调用 api 方法时所看到的那样。
我正在从事 Spring Boot 项目。我的项目中有存储库文件,但它会在存储库类中显示一条警告消息Unnecessary @Repository。我正在JpaRepository<>用我的存储库扩展 a 。我的 Spring 版本是4,JDK 版本是17。
这是我的依赖项
<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-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是我的存储库
@Repository // Here I get a warning to remove this annotation becasue its unnecessary
public interface CollegeRepo extends JpaRepository<College, Integer>{
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Maven 构建 Springboot 项目,但在 tomcat 服务器上运行时出现以下错误。
请提出解决方案。谢谢 。
java: Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NoSuchMethodError: 'boolean com.sun.tools.javac.code.Symbol$TypeSymbol.isLocal()'
Run Code Online (Sandbox Code Playgroud)
龙目岛
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
梅文
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /usr/local/Cellar/maven/3.8.4/libexec
Java version: 11.0.11, vendor: AdoptOpenJDK, runtime: /Users/psingh/.jabba/jdk/adopt@1.11.0-11/Contents/Home
Default locale: en_IN, platform encoding: US-ASCII
OS name: "mac os x", version: "11.1", arch: "x86_64", family: "mac"
Run Code Online (Sandbox Code Playgroud)
雄猫
Using CATALINA_BASE: /usr/local/Cellar/tomcat@9/9.0.55/libexec
Using CATALINA_HOME: /usr/local/Cellar/tomcat@9/9.0.55/libexec
Using CATALINA_TMPDIR: /usr/local/Cellar/tomcat@9/9.0.55/libexec/temp
Using JRE_HOME: /Users/psingh/.jabba/jdk/adopt@1.11.0-11/Contents/Home
Using CLASSPATH: /usr/local/Cellar/tomcat@9/9.0.55/libexec/bin/bootstrap.jar:/usr/local/Cellar/tomcat@9/9.0.55/libexec/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED …Run Code Online (Sandbox Code Playgroud) 在我的 Java Spring Boot 项目中,我尝试将 User 实体迁移到 mysql 数据库中。
当我 mvn spring-boot:run 时,我看到以下错误:
HHH90000026: MySQL57Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
Run Code Online (Sandbox Code Playgroud)
这是我的 application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?createDatabaseIfNotExist=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database=mysql
Run Code Online (Sandbox Code Playgroud)
这是mysql的依赖关系:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
我正在使用 Spring Boot 3.0.2 和 Spring Security 构建一个 API,我已经构建了安全过滤器链,并且它在阻止未经身份验证的请求方面工作正常。但我有一个RestController接受 的类application/json,如果我没有正确提供内容类型标头,我希望返回 415 状态代码。如果没有 Spring Security 的阻碍,它会得到很好的返回。但对于 Spring Security 来说,它似乎被拦截并返回 403。
WebSecurityConfig:
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.cors().and()
.csrf().disable()
.authorizeHttpRequests(auth -> auth
.requestMatchers("/auth**").permitAll()
.anyRequest().authenticated())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
.userDetailsService(jpaUserDetailsService)
.build();
}
Run Code Online (Sandbox Code Playgroud)
验证过滤器:
@Component
@RequiredArgsConstructor
public class JwtAuthFilter extends OncePerRequestFilter {
private final JwtUtils jwtUtils;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String jwtToken = request.getHeader(AUTHENTICATION_HEADER); …Run Code Online (Sandbox Code Playgroud) 是否可以配置千分尺在春季将跟踪信息发送到otel容器?
我轻松配置了向 Zipkin 和 Wavefront 发送跨度: https://docs.spring.io/spring-boot/docs/3.1.0-SNAPSHOT/reference/htmlsingle/#actuator.micrometer-tracing.tracers但没有关于导出的内容到酒店。
Micrometer 文档也没有提到将跨度导出到 otel 容器https://micrometer.io/docs/tracing#_using_micrometer_tracing_directly
spring boot 3 需要在 pom.xml 中包含哪些依赖项才能成功运行
我正在尝试将更新的 Spring Security 集成到我的项目中,而不是使用已弃用的extending WebSecurityConfigurerAdapter. 我已经建立了一个很好的系统,用户可以在其中进行身份验证(User实现UserDetails- 我正在使用 Hibernate)并生成令牌。我在这次登录中得到了 200 并收到了一个令牌。这个认证部分工作正常。
现在的问题是我的用户具有角色(例如ADMIN,,USER...)这些角色被添加到生成的令牌中。我的控制器获得@PreAuthorize注释。请求无法通过这些注释并受到禁止。当我不使用 时@PreAuthorize,请求将使用令牌进行验证。
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
private RSAKey rsaKey;
private final DefaultUserDetailsService defaultUserDetailsService;
public SecurityConfig(DefaultUserDetailsService defaultUserDetailsService) {
this.defaultUserDetailsService = defaultUserDetailsService;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.cors(Customizer.withDefaults())
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/auth/**").permitAll()
.anyRequest().authenticated()
)
.userDetailsService(defaultUserDetailsService)
.sessionManagement(session -> …Run Code Online (Sandbox Code Playgroud) 我有这样的方法
@Modifying( clearAutomatically = true )
@Query( "update versioned LookupMaster set state = 'PUBLISHED' , value = newValue, newValue = null, updatedDate = current_timestamp where ( name = :tableName and state = 'MODIFIED')" )
void commitLookupTableChanges( String tableName );
Run Code Online (Sandbox Code Playgroud)
在 springboot 3 升级之前它可以工作。springboot 升级到版本 3.0.2 后面临如下验证错误。
Caused by: java.lang.IllegalArgumentException: org.hibernate.query.SemanticException: The assignment expression type [java.lang.String] did not match the assignment path type [com.nokia.nsw.lookuptable.model.RowState] for the path [alias_2093546827.state] [update versioned LookupMaster set state = 'PUBLISHED' , value = newValue, newValue = …Run Code Online (Sandbox Code Playgroud) spring-boot ×10
java ×5
spring ×4
hibernate ×1
jpa ×1
jwt ×1
lombok ×1
maven ×1
micrometer ×1
option-type ×1
sdk ×1
spring-mvc ×1