无法使用gradle boot运行springboot应用程序



正在创建springboot应用程序,但无法运行

下面是我的Application类的样子

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
@EnableConfigurationProperties
public class ApplicationMain implements CommandLineRunner {
@Autowired
private CloudStorage cloudSt;
public static void main(String[] args){
SpringApplication app = new SpringApplication(ApplicationMain.class);
app.run();
}
public void run(String... args) throws Exception {
System.out.println("--------------");
cloudSt.print();
}
}

我使用命令gradle bootRun运行这个应用程序,它给出以下输出

❯ gradle bootRun
> Task :bootRun
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
BUILD SUCCESSFUL in 1s
4 actionable tasks: 4 executed

请注意没有错误。

注意:我正在构建一个将用作Jar文件的应用程序,但我正在测试这作为命令行应用程序,以验证属性是否被正确注入。供参考,这里是我的CloudStoragebean

@Component
@ConfigurationProperties(prefix = "cloud.storage")
public class CloudStorage {
@Value("${accountName}")
private String accountName;
@Value("${key}")
private String key;
@Value("${containerName}")
private String containerName;
public AzureBlobDirectory getAzureRootDirectory() throws CloudStorageException {
try {
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.parse(buildConnectionString(accountName, key));
CloudBlobClient cloudBlobClient = cloudStorageAccount.createCloudBlobClient();
return new AzureBlobDirectory(cloudBlobClient, containerName);
} catch (URISyntaxException ex) {
throw new CloudStorageException(ex);
} catch (InvalidKeyException ex) {
throw new CloudStorageException(ex);
}
}
private String buildConnectionString(String accountName, String accountKey){
return String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s", accountName, accountKey);
}
public void print() {
System.out.printf("%s --- %s --- %sn", accountName, key, containerName);
}
}
  • 我配置我的springboot应用程序错误吗?
  • 我在这里错过了什么,为什么我看不到主类的打印语句

您似乎缺少一个与SLF4J集成的日志框架:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

因此,它默认为无操作实现,这意味着日志消息不会输出到任何地方:

SLF4J: Defaulting to no-operation (NOP) logger implementation

在Spring Boot应用程序中,与SLF4J集成的默认日志框架是Logback。它应该通过对spring-boot-starterspring-boot-starter-*的依赖在类路径上。

可以使用@Slf4j注释

@Component
@Slf4j
@ConfigurationProperties(prefix = "cloud.storage")
public class CloudStorage {
@Value("${accountName}")
private String accountName;
@Value("${key}")
private String key;
@Value("${containerName}")
private String containerName;
public AzureBlobDirectory getAzureRootDirectory() throws CloudStorageException {
try {
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.parse(buildConnectionString(accountName, key));
CloudBlobClient cloudBlobClient = cloudStorageAccount.createCloudBlobClient();
return new AzureBlobDirectory(cloudBlobClient, containerName);
} catch (URISyntaxException ex) {
log.error(ex.toString());
throw new CloudStorageException(ex);
} catch (InvalidKeyException ex) {
log.error(ex.toString());
throw new CloudStorageException(ex);
}
}
private String buildConnectionString(String accountName, String accountKey){
return String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s", accountName, accountKey);
}
public void print() {
log.info("%s --- %s --- %sn", accountName, key, containerName);
}
}