我一直使用windows进行软件开发。我不知道 MacOS 的内部结构。我知道 Xcode 软件用于开发 iOS/Mac 应用程序,但我不需要它。
对于我的用例,我能够使用 BigSur在我的Intel Mac上安装intellij、Java、Docker、Minikube 和 Visual-Studio-Code ...我能够在 Docker 容器中的本地工作数据库中运行简单的微服务。
但是当我尝试使用 Git 时,我遇到了这个问题:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
我认为这与Xcode有关。我不想碰它,
所以我尝试通过brew安装Git 。
brew install git但出现错误
Error: git 2.29.2 is already installed
所以我尝试进行更新
brew upgrade git,但再次出现以下错误。
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
我还尝试删除 Git 进行全新安装
brew remove git,并且没有错误,但随后我再次使用 brew 安装 git 并出现相同的错误。
有没有办法在没有 Xcode 的情况下安装 Git? 我不想在我的机器上安装不必要的软件,我不需要的东西。
我有一个@RestController 在字段中只有一个依赖项@Autowire
,依赖项是@component,该组件类定义有一些自动装配的字段,它们是@service,这些服务有一些@repositories。
在整个流程中,我使用了 kafka、Quartz、Cassandra 和 DB2,因此当我为控制器创建单元测试用例时,我不想设置整个应用程序。所以我决定使用 @webMvcTest 并在我唯一的一个控制器类依赖项上使用 @MockBean。
但我的测试抛出异常,因为它试图创建一个 Dao bean,它被标记为 @repository。
@ActiveProfiles("test")
@WebMvcTest(controllers = MyControllerTest .class)
class MyControllerTest {
@MockBean
MyControllerDependency dependency;
@Autowired
MockMvc mockMvc;
@Test
void test_something() throws Exception {
assert(true);
}
}
Run Code Online (Sandbox Code Playgroud)
这是代码的过于简化的版本
@Component
class MyControllerDependency {
@AutoiWired
MyCustomService service;
}
@Service
class MyCustomService{
@Autowired
MyCustomDao dao;
}
@Repository
class MyCustomDao{
@Autowired
private JdbcTemplate template;
}
Run Code Online (Sandbox Code Playgroud)
我在测试中遇到以下异常。
Exception
***************************
APPLICATION FAILED TO START
***************************
Description:
Field template in com.....MyCustomDao` required a bean of …Run Code Online (Sandbox Code Playgroud) 我正在对一个非常旧的应用程序进行更改。这是使用 Spring MVC 4。
我需要在 Spring 控制器的 JSP 中从 form:form 标签中发布数据。UI 是固定的,我只能在服务器端进行更改。基于我提交的表单中的特定字段,我希望在我的 Controller Handler 方法参数中有正确的子对象实例。
例如,
class Payment {...}
class CardPayment extends Payment{...}
class CheckPayment extends Payment{...}
Run Code Online (Sandbox Code Playgroud)
在 UI 表单中,会有一个名为 paymentType 的输入值。付款将是 commandObject 或 ModelAttribute
我希望我的 @PostMapping 控制器在参数中具有正确的子对象。我不想在控制器代码中手动实例化它。
@PostMapping
public ModelAndView doSomePay(@ModelAttribute("payment") Payment paymentInput, BindingResult result){
Run Code Online (Sandbox Code Playgroud)
现在我希望paymentInput上面的这个对象是 CardPayment 或 checkPayment 类型。
我试图创建一个@initBinder and WebDatabinder但实际上我有近 10 个子类,我是否需要为所有这些创建“编辑器”?
如果是,那么短而快速地创建 propertyEditor 的最佳方法是什么
@InitBinder
public void initBinder(WebDataBinder binder, HttpServletRequest request) {
String paymentType = request.getParameter("paymentType");
PropertyEditor productEditor;
//somehow I can …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过扩展在我的应用程序中配置 CassandraCassandraAutoConfiguration
我使用 springCassandraRepository进行数据库访问,并使用带有o.s.d.cassandra.core.mapping.Table注释的类来定义我的表。
我还配置了以下属性以及集群所需的其他属性
spring:
data:
cassandra:
schema-action: CREATE_IF_NOT_EXISTS
Run Code Online (Sandbox Code Playgroud)
但应用程序启动时 Cassandra 中不会创建任何表。
schemaAction在CassandraProperties 不工作。
如果我在启动时ApplicationRunner通过使用以编程方式创建表cassandraTemplate.getCqlOperations().execute(...),那么一切都会正常工作。
在这种情况下,我可以使用我的存储库。find() 和 save() 方法。只是为了证明我的@table类写得正确
这里有 2 个代码片段,它们应该返回与我HashMap在map factory. 但是第二个代码片段不能在 IntelliJ 中编译。这两个代码在 Eclipse 中都可以正常工作。
System.out.println方法需要一些可以调用的东西toString,但是在 IntelliJ 中我得到了这个奇怪的错误,为什么?
可编译代码(Eclipse 和 IntelliJ):
System.out.println(Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
Collectors.counting())));
Run Code Online (Sandbox Code Playgroud)
错误代码(在 Eclipse 中有效,但仅在 IntelliJ 中失败):
System.out.println(Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
HashMap::new,
Collectors.counting())));
Run Code Online (Sandbox Code Playgroud)
IntelliJ 中第二个片段的错误
Required type: String
Provided: Map
<java.lang.String,java.lang.Long> no instance(s) of type variable(s) K, V exist so that HashMap<K, V> conforms to String
Run Code Online (Sandbox Code Playgroud) 有人可以建议,为什么我不能在这里应用方法参考?
工作代码。
System.out.println(
Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(Function.identity(),Collectors.counting())));
Run Code Online (Sandbox Code Playgroud)
编译错误,无法解析方法
System.out.println(
Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(Function::identity,Collectors::counting)));
Run Code Online (Sandbox Code Playgroud) 我有一个 Foo 列表,在每个 Foo 上,我应用了一个处理器方法来获取ValidItem.
如果处理中出现错误,那么我返回ErrorItem.
现在如何通过 Java 8 流处理它以得到 2 个不同列表形式的结果
List<Foo> FooList = someList....;
class ValidItem extend Item{......}
class ErrorItem extend Item{......}
Item processItem(Foo foo){
return either an object of ValidItem or ErrorItem;
}
Run Code Online (Sandbox Code Playgroud)
我相信我能做到
Map<Class,List<Item>> itemsMap =
FooList
.stream()
.map(processItem)
.collect(Collectors.groupingBy(Object::getClass));
Run Code Online (Sandbox Code Playgroud)
但作为List<Parent>不是一个List<Child>让我无法强制转换地图结果变成List<ValidItem>
现实ErrorItem,并ValidItem在所有,没有关系只是为这种蒸汽处理和processItem方法我着想两个完全不同的类让他们在同一层次通过扩展标记项目班级,。
在代码中的许多其他地方,我不能/不应该将 ValidItem 称为 Item ,因为它给出了它也可以是 ErroItem 的想法。
是否有使用流的正确方法,最后我得到 2 个列表。和 ErrorItem 和 ValidItem 没有扩展相同的 Item 类?
############## 更新##############
正如我所说的 ValidItem 和 …
有没有办法为流的每个元素创建 2 个不同的对象并最后收集它们?
例如,如果我有 aList<String> stringList并且有一个GoddClass带有默认值和 a 的类customConstructor,我想在一个流中创建 2 个对象并最后收集
stringList
.stream()
.map(GoddClass::new)
.addAnothrObject(GoddClass::customConstructor) // Not a valid line, Just to depict what is needed
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
一个流可能不是实现我正在尝试的目标的正确解决方案。但这个问题留给专家们来解答。
java-8 ×4
collectors ×3
java ×3
java-stream ×3
spring ×3
cassandra ×1
datastax ×1
eclipse ×1
git ×1
homebrew ×1
intellij-14 ×1
spring-boot ×1
spring-form ×1
spring-mvc ×1
spring-test ×1
xcode ×1