小编use*_*926的帖子

没有定义类型的唯一bean:期望的单个匹配bean但找到2

我在部署代码时遇到以下异常

 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.belk.api.adapter.contract.Adapter] is defined: expected single matching bean but found 2: [endeca, solar]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:800)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    ... 64 more
Run Code Online (Sandbox Code Playgroud)

我有3个不同的项目,一个是Common,第二个是Adapter,第三个是Service.适配器依赖于Common,而Service依赖于Adapter.这三个都是maven项目.现在在我的Common项目中,我有一个名为CommonAdapter.java的接口

 public interface CommonAdapter {
    List service() ;
}
Run Code Online (Sandbox Code Playgroud)

我在同一个项目中有一个名为AdapterFactory.java的类(i,e Common)

@Component
public class AdapterFactory {
    @Autowired
    Adapter adapter;
    public Adapter getAdapter(String adapterName){
        return adapter;
    }

}   
    <context:component-scan base-package="com.test.api" />
    <bean
        class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean"
        id="adapterFactory">
        <property name="serviceLocatorInterface" value="com.test.api.adapter.manager.AdapterFactory">
        </property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

现在在我的Adapter Project中,我有CommonAdapter.java的实现类,一个是EndecaAdapetr.java,另一个是SolarAdapter.java

@Component("endeca")
public class EndecaAdapter implements Adapter {
    List service() { …
Run Code Online (Sandbox Code Playgroud)

java spring javabeans

7
推荐指数
2
解决办法
4万
查看次数

com.fasterxml.jackson.core.JsonParseException:读取 json 文件时出现意外字符(代码 160)

我正在从文件中读取以下 json 内容并转换为地图,但出现以下异常。请让我知道是否有人遇到过这样的问题。我验证了我的 json 内容并且看起来有效。不知道为什么这个错误。

JSON 内容:

{
    "Results":[{         
        "TotalPositiveFeedbackCount": 0      
    },{
        "TotalPositiveFeedbackCount": 1      
    }   ]
}
Run Code Online (Sandbox Code Playgroud)

代码:

Map<String, Object> domainMap = new HashMap<String, Object>();
try {
    responseJson = getFile("reviewresponse.json");
    //responseJson = new String(Files.readAllBytes(Paths.get("reviewresponse.json")), StandardCharsets.UTF_8);
    ObjectMapper jsonObjectMapper = new ObjectMapper();
    jsonObjectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    domainMap = jsonObjectMapper.readValue(responseJson,
                   new TypeReference<Map<String, Object>>() {});
} 
Run Code Online (Sandbox Code Playgroud)

异常详情:

com.fasterxml.jackson.core.JsonParseException: Unexpected character (' ' (code 160)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name
 at [Source: {
    "Results":[{         
        "TotalPositiveFeedbackCount": …
Run Code Online (Sandbox Code Playgroud)

java json jakarta-ee

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

标签 统计

java ×2

jakarta-ee ×1

javabeans ×1

json ×1

spring ×1