【问题标题】:Nosuchfileexception Error on java while running and trying to load data in Cassandra运行并尝试在 Cassandra 中加载数据时 java 出现 Nosuchfileexception 错误
【发布时间】:2022-01-14 20:46:24
【问题描述】:

我不断收到此错误,路径已在 yml 中指定,即使在控制台中它也会转到相对路径但没有读取文件或找到它,我该如何解决? I have attached the picture 及以下是我的主要方法中的代码。任何输入都深表感谢。谢谢!

@SpringBootApplication
@EnableConfigurationProperties(DataStaxAstraProperties.class)
public class BookAppApplication {

    @Autowired AuthorRepostories authorRepostories;
    
    @Value("${datadump.location.author}")
    private String authorDumpsLocation;
    
    @Value("${datadump.location.works}")
    private String authorWorksLocation;
    
    public static void main(String[] args) {
        SpringApplication.run(BookAppApplication.class, args);
    }
    
    private void initAuthors() {
        Path path = Paths.get(authorDumpsLocation);
        System.out.println(path.toAbsolutePath());
        try(Stream<String> lines = Files.lines(path)){
            lines.forEach(line->{
                String jsonStr = line.substring(line.indexOf("{"));
                try {
                    JSONObject jsonObject = new JSONObject(jsonStr);
                    Author author = new Author();
                    author.setName(jsonObject.optString("name"));
                    author.setPersonalName(jsonObject.optString("personal_name"));
                    author.setId(jsonObject.optString("key").replace("/authors/",""));
                    
                    System.out.println("Saving author" + author.getName() + "....");
                    authorRepostories.save(author);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    private void initWorks() {
        
    }
    
    @PostConstruct
    public void start() {
        initAuthors();
        initWorks();
    }

    @Bean
    public CqlSessionBuilderCustomizer sessionBuilderCustomizer(DataStaxAstraProperties astraProperties) {
        Path bundle = astraProperties.getSecureConnectBundle().toPath();
        return builder -> builder.withCloudSecureConnectBundle(bundle);
    }

}

【问题讨论】:

    标签: java cassandra


    【解决方案1】:

    找到了问题。与访问权限有关。 Java 无法访问这些文件,因为它在更改文件的属性后受到保护,它可以工作。

    【讨论】:

      猜你喜欢
      • 2020-04-10
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      • 2021-03-03
      • 2019-08-02
      相关资源
      最近更新 更多