Das Laden von Ressourcen mit Springboot @Value und Javafx erfordert, dass Dateien in Ressourcen/statisch mit Java 9 -ModJava

Java-Forum
Anonymous
 Das Laden von Ressourcen mit Springboot @Value und Javafx erfordert, dass Dateien in Ressourcen/statisch mit Java 9 -Mod

Post by Anonymous »

Wie der Titel sagt. So laden Sie eine XML-Datei (und jede andere Datei für diese Angelegenheit) über die Annotation von Spring Boots Value. Wenn der statische Unterordner nicht einbezogen wird, führt dies zu einer FilenotfoundException. < /p>
Kann jemand erklären, warum dies der Fall ist? Zu den Lösungen gehört das Löschen der Datei modul-info.java , das Entfernen der org.openjfx.javafxplugin importieren oder wie angegeben, die XML in Ressourcen/Static/test/ verschieben oder nicht verwenden die Wertannotation, aber ich habe im Allgemeinen Schwierigkeiten, Module zu verstehen, und bin daher neugierig, warum dieses Problem auftritt. p>

Code: Select all

build.gradle
src
├───main
│   ├───java
│   │   │   module-info.java
│   │   │
│   │   └───com
│   │       └───example
│   │               App.java
│   │               TestLoader.java
│   │
│   └───resources
│       │   application.properties
│       │
│       ├───static
│       │   └───test
│       │           test.xml
│       │
│       └───test
│               test.xml
│
└───test
├───java
│   └───com
│       └───example
│               TestTest.java
│
└───resources
unused

< /code>
unused
ist eine leere Datei, die zum Generieren des Testressourcenordners erforderlich ist und einen Fehler vermeiden kann.package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App
{
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
< /code>
Loader:
package com.example;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class TestLoader
{
private TestLoader(@Value("classpath:test/test.xml") Resource fxml) throws IOException
{
fxml.getInputStream();
}
}
< /code>
Module info:
module com.example {
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.context;
requires spring.core;
requires spring.beans;

opens com.example to spring.beans, spring.context, spring.core;
}
< /code>
Gradle build file:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.springframework.boot' version '3.4.2'
id 'io.spring.dependency-management' version '1.1.7'
}

group 'com.example'
version '0.0.1-SNAPSHOT'

repositories {
mavenCentral()
}

java {
modularity.inferModulePath = true
}

application {
mainModule = 'com.example'
mainClass = 'com.example.App'
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'

testImplementation('org.springframework.boot:spring-boot-starter-test'){
// https://github.com/spring-cloud/spring- ... issues/142
exclude group: "com.vaadin.external.google", module:"android-json"
}
testImplementation("org.junit.jupiter:junit-jupiter-api")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
useJUnitPlatform()
}
< /code>
Test:
package com.example;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class TestTest {
@Autowired
TestLoader loader;

@Test
public void test() {
}
}

< /code>
I have reviewed similar questions, but they all concern different questions. Thanks in advance!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post