1. Konfigurationsdatei
Die Codekopie lautet wie folgt:
<bean id = "configProperties"
>
<Eigenschaft name = "Ort" value = "classPath: jdbc.properties"/>
</bean>
2. Lesen Sie die Attributmethode
Die Codekopie lautet wie folgt:
ApplicationContext c = new classpathXmlApplicationContext ("classPath: applicationContext-datasource.xml");
Eigenschaften p = (Eigenschaften) cGetbean ("configProperties");
System.out.println (P.GetProperty ("jdbcorcale.driverClassName");
Ein anderer Freund bietet eine Möglichkeit, die Frühlingskonfigurationsdatei zu lesen. Bitte teilen Sie sie.
Direkte Lesemethode:
Die Codekopie lautet wie folgt:
öffentlicher void test () wirft ioException aus
{
Ressourcenressourcen = applicationContextFactory.getApplicationContext (). GetResource ("ClassPath: com/SpringDemo/Ressource/test.txt");
Datei Datei = Resource.getFile ();
byte [] buffer = new byte [(int) file.length ()];
FileInputStream ist = new FileInputStream (Datei);
is.read (puffer, 0, buffer.length);
IS.CLOSE ();
String str = new String (Puffer);
System.out.println (str);
}
Lesen Sie die Federkonfiguration durch:
Die Codekopie lautet wie folgt:
Paket com.springdemo.resource;
import org.springframework.core.io.resource;
öffentliche Klasse Resourcebean {
private Ressourcenressource;
öffentliche Ressource getResource () {
Ressource zurückgeben;
}
public void setResource (Ressourcenressource) {
this.resource = Ressource;
}
}
Federbohnenkonfiguration:
Die Codekopie lautet wie folgt:
<!-Sie können dem Ressourcenattribut des Ressourcentyps direkt einen Dateipfad zuweisen.
<bean id = "ressourceBean">
<Eigenschaft name = "ressourcen" value = "classPath: /com/springdemo/resource/test.txt"> </Property>
</bean>