Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
Du hast recht es ist oben etwas missverständlich. Mir geht es um das Schreiben einer Klasse für eigene Configurationswerte.Ein 'Rechtsklick -> new File' reicht dir vermutlich nicht als Antwort?
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource("classpath: app.properties")
public class Config {
public Config() {
super();
// TODO Auto-generated constructor stub
}
@Value( "${key.something}" )
private String something;
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
}
key.something=val
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigTest {
private Config config;
@Before
public void setUp() throws Exception {
config = new Config();
}
@Test
public void testGetSomething() {
assertEquals("Something: " + config.getSomething(), "val", config.getSomething());
}
}
Du benutztKann mir hier jemand helfen und mir sagen was ich gerad falsch mache?
new, lass dir stattdessen einfach die Instanz von Spring injecten