Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到能够从类型[java.lang.String]转换为类型[@Autowired@ManyToOne@JoinColumn com.papertrue.country.country]的转换器_Java_Spring Boot_Jpa_Spring Data Jpa - Fatal编程技术网

未找到能够从类型[java.lang.String]转换为类型[@Autowired@ManyToOne@JoinColumn com.papertrue.country.country]的转换器

未找到能够从类型[java.lang.String]转换为类型[@Autowired@ManyToOne@JoinColumn com.papertrue.country.country]的转换器,java,spring-boot,jpa,spring-data-jpa,Java,Spring Boot,Jpa,Spring Data Jpa,因此,我对JPA还很陌生,在将一个对象映射到另一个对象时,我被卡住了。这是我的用户实体: package com.papertrue.user; 进口com.papertrue.country.country; 导入com.papertrue.currency.currency; @实体 @配置属性(“用户”) @表(name=“users”) 公共类用户{ @身份证 @列(name=“id”) 私有字符串用户标识; 私有字符串名称; @列(name=“phone\u ext”) 私有字符串ph

因此,我对JPA还很陌生,在将一个对象映射到另一个对象时,我被卡住了。这是我的用户实体:

package com.papertrue.user;
进口com.papertrue.country.country;
导入com.papertrue.currency.currency;
@实体
@配置属性(“用户”)
@表(name=“users”)
公共类用户{
@身份证
@列(name=“id”)
私有字符串用户标识;
私有字符串名称;
@列(name=“phone\u ext”)
私有字符串phoneExt;
@列(name=“电话号码”)
私有字符串phoneNo;
私人字符串电子邮件;
@manytone(fetch=FetchType.EAGER)
@JoinColumn(name=“country”)
私人国家;
@manytone(fetch=FetchType.LAZY)
@JoinColumn(name=“currency”)
私人货币;
@列(name=“fb_id”)
私有字符串facebookId;
@列(name=“google\u id”)
私有字符串googleId;
@列(name=“当前余额”)
私人国际收支平衡;
@列(name=“已启用”)
私有布尔值被禁用;
@列(name=“免费样本使用”)
私有布尔是自由抽样的;
@列(name=“client\u id”)
私有字符串clientId;
}
我国实体:

package com.papertrue.country;
导入com.papertrue.currency.currency;
@实体
@配置属性(“国家”)
@表(name=“countries”)
公营国家{
@身份证
私有字符串码;
私有字符串名称;
@manytone(fetch=FetchType.LAZY)
@JoinColumn(name=“currency”)
私人货币;
@列(name=“isd\u ext”)
私有字符串ISDExt;
@枚举(EnumType.STRING)
私有过渡区;
}
和我的货币实体:

package com.papertrue.currency;
@实体
@配置属性(“货币”)
@表(名称=“货币”)
公营货币{
@身份证
私有字符串码;
私有字符串符号;
私有字符串名称;
私有整数乘法器;
@列(name=“minVal”)
私人价值;
}
所以,当我在国家对象中映射货币时,它就起作用了,但当我在用户和国家对象中做同样的事情时,它就不起作用了。我得到的是
org.springframework.core.convert.ConverterNotFoundException
。以下是错误:

java.lang.IllegalStateException:无法加载ApplicationContext
在org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)~[spring-test-5.3.0.jar:5.3.0]
原因:org.springframework.boot.context.properties.ConfigurationPropertiesBindException:创建名为“user com.papertrue.user.user”的bean时出错:无法将属性绑定到“user”:前缀=user,ignoreInvalidFields=false,ignoreUnknownFields=true;嵌套异常为org.springframework.boot.context.properties.bind.BindException:未能将“user.country”下的属性绑定到com.papertrue.country.country
... 省略70个公共框架
原因:org.springframework.boot.context.properties.bind.BindException:无法将“user.country”下的属性绑定到com.papertrue.country.country
... 89省略公共框架
原因:org.springframework.core.convert.ConverterNotFoundException:未找到能够从类型[java.lang.String]转换为类型[@javax.persistence.ManyToOne@javax.persistence.JoinColumn com.papertrue.country.country]的转换器
... 105省略公共帧
这是在我运行测试时发生的:

package com.papertrue;
导入org.junit.jupiter.api.Test;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.autoconfigure.springboot应用程序;
导入org.springframework.boot.test.context.SpringBootTest;
导入com.papertrue.exceptions.PaperTrueUserNotFoundException;
导入com.papertrue.user.UserService;
@春靴测试
公共类UserServiceTest{
@自动连线
私人用户服务;
@试验
public void contextLoads(){
//测试getEmailInstance
System.out.println(“=======getEmailInstance()=====”;
试一试{
System.out.println(userService.getEmailInstance(“text@papertrue.com);
}捕获(PaperTrueUserNotFounde异常){
e、 printStackTrace();
}
}
@SpringBoot应用程序
静态类测试配置{
}
}
用户服务服务:

package com.papertrue.user;
导入java.util.Optional;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.context.properties.EnableConfigurationProperties;
导入org.springframework.stereotype.Service;
导入com.papertrue.exceptions.PaperTrueUserNotFoundException;
@服务
@EnableConfigurationProperties(User.class)
公共类用户服务{
@自动连线
私有用户存储库用户存储库;
/**
*返回其电子邮件与参数email的值匹配的用户。
* 
*@param电子邮件
*@返回
*@抛出PaperTrueUserNotFoundException
*/
公共用户getEmailInstance(字符串电子邮件)引发PaperTrueUserNotFoundException{
可选=userRepository.findByEmail(电子邮件);
if(可选的.isPresent()){
返回可选的.get();
}
抛出新的PaperTrueUserNotFoundException(“未找到用户”);
}
}
和存储库以供参考:

package com.papertrue.user;
导入java.util.Optional;
导入org.springframework.data.jpa.repository.JpaRepository;
导入org.springframework.stereotype.Repository;
@存储库
公共接口用户存储库扩展了JpaRepository{
可选findByEmail(字符串电子邮件);
}

异常告诉您无法按照
@ConfigurationProperties
的建议设置配置属性。因为对于国家/地区,它有一个
字符串
值(