小编so_*_*ser的帖子

为什么Gradle编译在此示例中失败?

我正在阅读一本介绍Spring Framework的书,我被困在第一个例子上.我之前从未使用过Gradle.不知何故,编译器不理解我的代码中使用的注释.即使我在gradle.build文件中使用了spring依赖项.

为了完整起见,我将发布此示例中的所有4个文件.

的build.gradle:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = System.getProperty("mainClass")

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.springframework:spring-context:4.0.5.RELEASE'
}
Run Code Online (Sandbox Code Playgroud)

MessageService.java:

package com.apress.isf.spring;

public interface MessageService {

 public String getMessage();

}
Run Code Online (Sandbox Code Playgroud)

HelloWorldMessage.java:

package com.apress.isf.spring;



public class HelloWorldMessage implements MessageService {

 public String getMessage(){

 return "Hello World";

 }

}
Run Code Online (Sandbox Code Playgroud)

Application.java:

package com.apress.isf.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@Configuration
@ComponentScan
public class Application {

 @Bean
 MessageService helloWorldMessageService() {

    return new HelloWorldMessage();

 }

 public static void …
Run Code Online (Sandbox Code Playgroud)

java spring annotations compilation gradle

5
推荐指数
1
解决办法
2966
查看次数

如何在 Java 中创建虚拟文件列表?

我需要创建一个List<File> files,以便它包含 3 个虚拟文件。我怎么做?

我需要它进行单元测试。

我做了

private File file1 = mock(File.class);
private File file2 = mock(File.class);
private File file3 = mock(File.class);

List<File> files = Lists.newArrayList(file1, file2, file3);
Run Code Online (Sandbox Code Playgroud)

但我认为这一切都是可能的。

java junit list mockito dummy-data

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

标签 统计

java ×2

annotations ×1

compilation ×1

dummy-data ×1

gradle ×1

junit ×1

list ×1

mockito ×1

spring ×1