标签: spring-framework-beans

无法找到“org.springframework.http.codec.ServerCodecConfigurer”类型的bean

应用程序无法启动


描述:

方法的参数0modifyRequestBodyGatewayFilterFactoryorg.springframework.cloud.gateway.config.GatewayAutoConfiguration类型需要一个bean 'org.springframework.http.codec.ServerCodecConfigurer',可能不会被发现。

行动:

考虑'org.springframework.http.codec.ServerCodecConfigurer'在您的配置中定义一个类型的 bean 。

选择了 JAVA_TOOL_OPTIONS:-agentlib:jvmhook
选择了 _JAVA_OPTIONS:-Xbootclasspath/a:"C:\Program Files (x86)\HPE\Unified Functional Testing\bin\java_shared\classes\jasmine.jar"
选择了 JAVA_TOOL_OPTIONS: -agentlib: jvmhook

java spring javabeans spring-boot spring-framework-beans

11
推荐指数
2
解决办法
1万
查看次数

已弃用的 BasicAuthorizationInterceptor 的替代品是什么?

我正在使用新的 BasicAuthorizationInterceptor 在 oauth2.0 中进行基本身份验证。我找不到已弃用的 BasicAuthorizationInterceptor 的替代品。请帮我解决一下

java spring oauth-2.0 spring-framework-beans

8
推荐指数
1
解决办法
6946
查看次数

Springs BeanUtils.copyProperties() 对比 Apache Commons BeanUtils.copyProperties

试图在这里做一些简单的事情。获取一个 Entity 对象并将其同名属性复制到另一个 bean。

你可以用 Apache commons 做到这一点

org.apache.commons.beanutils.BeanUtils.copyProperties(source,target)
Run Code Online (Sandbox Code Playgroud)

但这里的问题是我们可能有一些特定于实体 bean 的属性(元数据,如 created、lastUpdated 等时间戳),我们不想复制到目标 bean 并且 Apache Commons BeanUtils 不支持忽略属性. 我被推向了 Spring BeanUtils 的方向

org.springframework.beans.BeanUtils.copyProperties(source,target,ignoreProperties)
Run Code Online (Sandbox Code Playgroud)

其中 ignoreProperties 是您要忽略的属性名称的字符串数组。现在的问题似乎是在执行此属性复制时,它会将源对象的属性设为 null!由于源对象是一个实体对象,当事务被提交时,我们会得到一个带有强制 id 字段的 HibernateException

org.hibernate.HibernateException: identifier of an instance {source} was altered from {originalId} to null
Run Code Online (Sandbox Code Playgroud)

任何人都知道解决这个问题的方法,或者您是否致力于使用其中一种?让我困惑的是为什么公地库不支持在复制时忽略属性,或者为什么 springframework BeanUtils 似乎执行剪切/粘贴而不是复制/粘贴。

java apache-commons apache-commons-beanutils spring-framework-beans

6
推荐指数
0
解决办法
6099
查看次数

我们需要 Spring Beans 中的静态字段吗?

我已经看到将 Logger 实例创建为用任何 Spring 的 Annotation ( @Component, @Service)注释的类的静态属性的一般做法。

因为,默认情况下创建的所有 bean 本质上都是单例的。我们真的需要这个 scnerio 中的静态字段,因为毕竟只有一次实例吗?

java spring spring-framework-beans

4
推荐指数
1
解决办法
1520
查看次数

在Spring Framework 5.1中注册具有相同名称的测试bean

我在生产文件中有以下配置:

@Configuration
internal class Config {

  @Bean
  fun clock() = Clock.systemUTC()
}
Run Code Online (Sandbox Code Playgroud)

在测试中:

@Configuration
class ClockTestConfiguration {

  @Bean
  fun clock() = SetableClock()
}
Run Code Online (Sandbox Code Playgroud)

我的测试注释:

@SpringBootTest(
  webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
  classes = [
    MyApplication::class,
    ClockTestConfiguration::class
  ]
)
class MyTest {
...
Run Code Online (Sandbox Code Playgroud)

当我使用Spring Boot时,2.0.5.RELEASE它就像一个魅力.2.1.0.RELEASE在bean注册期间升级到它失败.

Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'clock' defined in com.foo.clock.ClockTestConfiguration: 
Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=clockTestConfiguration; factoryMethodName=clock; initMethodName=null; destroyMethodName=(inferred); 
defined in com.foo.clock.ClockTestConfiguration] for …
Run Code Online (Sandbox Code Playgroud)

spring kotlin spring-boot spring-framework-beans

4
推荐指数
1
解决办法
2001
查看次数

异常:找不到“org.springframework.http.codec.ServerCodecConfigurer”类型的 bean

添加以下 Maven 依赖项后,我的程序中出现以下错误。

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.2.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)

错误

通过构造函数参数2表达的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“org.springframework.http.codec.ServerCodecConfigurer”类型的合格 bean:预计至少有 1 个符合自动装配候选资格的 bean。依赖注释:{}

行动:

考虑在配置中定义“org.springframework.http.codec.ServerCodecConfigurer”类型的 bean。

请建议如何创建 org.springframework.http.codec.ServerCodecConfigurer。


通过添加以下代码解决了该问题。

@Bean
public ServerCodecConfigurer serverCodecConfigurer() {
   return ServerCodecConfigurer.create();
}
Run Code Online (Sandbox Code Playgroud)

java javabeans spring-boot spring-framework-beans

3
推荐指数
1
解决办法
5387
查看次数

端点,Spring Security 配置返回:该方法无法确定模式是否为 Spring MVC

SecurityConfiguration 中的 SecurityFilterChain beans 返回此错误 我没有找到任何有关此方法的信息来解决该问题:

    @Configuration
    @EnableWebSecurity
    public class SecurityConfiguration {
        
          @Bean
            public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
                return  httpSecurity
                        .csrf(csrf -> csrf.disable())
                        .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                        .authorizeHttpRequests(authorize -> authorize
                                .requestMatchers(HttpMethod.POST, "/auth/login").permitAll()
                                .requestMatchers(HttpMethod.POST, "/auth/register").permitAll()
                                .requestMatchers(HttpMethod.POST, "/product").hasRole("ADMIN")
                                .anyRequest().authenticated()
                        )
                        .build();
            }
    }
Run Code Online (Sandbox Code Playgroud)

引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.security.web.SecurityFilterChain]:工厂方法“securityFilterChain”抛出异常并显示消息:此方法无法确定这些模式是否是Spring MVC模式。如果此端点是 Spring MVC 端点,请使用 requestMatchers(MvcRequestMatcher); 否则,请使用 requestMatchers(AntPathRequestMatcher)。

原因:java.lang.IllegalArgumentException:此方法无法确定这些模式是否是 Spring MVC 模式。如果此端点是 Spring MVC 端点,请使用 requestMatchers(MvcRequestMatcher); 否则,请使用 requestMatchers(AntPathRequestMatcher)。

spring-security spring-boot spring-framework-beans security-filter

3
推荐指数
1
解决办法
3071
查看次数

spring框架:预期单个匹配bean但找到2

这个超级DAO:

public class CrudDAO{

}
Run Code Online (Sandbox Code Playgroud)

这个孩子班:

@Repository
public class JnsTimeDao extends CrudDAO {

}

@Repository
public class BatchDAO extends CrudDAO {
}
Run Code Online (Sandbox Code Playgroud)

这个超级服务类

@Transactional(readOnly = true)
public abstract class CrudService<D extends CrudDAO> {

    @Autowired
    protected D dao;
}
Run Code Online (Sandbox Code Playgroud)

启动错误:

org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义[com.gp.dao.CrudDAO]类型的限定bean:期望的单个匹配bean但找到2:batchDAO,jnsTimeDao

spring spring-framework-beans

2
推荐指数
1
解决办法
5663
查看次数