小编Khu*_*uzi的帖子

无法自动装配字段:Spring启动应用程序中的RestTemplate

在启动期间运行spring boot应用程序时,我遇到异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.client.RestTemplate com.micro.test.controller.TestController.restTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Run Code Online (Sandbox Code Playgroud)

我在TestController中自动装配RestTemplate.我正在使用Maven进行依赖管理.

TestMicroServiceApplication.java

package com.micro.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TestMicroServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestMicroServiceApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

TestController.java

    package com.micro.test.controller; …
Run Code Online (Sandbox Code Playgroud)

spring maven resttemplate spring-boot

86
推荐指数
5
解决办法
8万
查看次数

错误:无此类属性:类GradleVersion:JetGradlePlugin

我在gradle项目的intellij中遇到错误。我正在导入现有的gradle项目,并尝试在gradle窗口中刷新它。

Error:No such property: GradleVersion for class: JetGradlePlugin
Run Code Online (Sandbox Code Playgroud)

请指教。

java intellij-idea gradle

21
推荐指数
3
解决办法
4万
查看次数

为什么这些Java 8 lambdas在类型转换期间表现不同?

Stream st = Stream.of(1,2,3,4);
Run Code Online (Sandbox Code Playgroud)

这是创建整数流(通过在运行时推断)还是对象流?

st.collect(Collectors.averagingInt((Integer x)->x));
Run Code Online (Sandbox Code Playgroud)

这条线很好.

st.forEach((Integer x)-> System.out.println(x));
Run Code Online (Sandbox Code Playgroud)

这行不编译.它在(整数x)处给出一个编译错误,说出预期的对象但是找到了Integer.为什么?

为什么上面的averagingInt方法没有抱怨相同?

averagingInt将ToIntFunction接口作为原始引用类型,<? super T>并允许Integer值.虽然forEach正在使用与原始引用类型相同的Consumer接口,<? super T>但编译器正在抱怨Integer参数值.

java java-8 java-stream

9
推荐指数
1
解决办法
232
查看次数