我有一个应用程序,其中包含application.properties中列出的许多数据源设置.我有一个@ConfigurationProperties
加载这些设置的类.现在我想从这个ConfigurationProperties
类中获取值并使用它们来动态创建DataSource bean.我尝试过使用@PostConstruct
和实现BeanFactoryPostProcessor
.但是,BeanFactoryPostProcessor
处理似乎很早就发生了 - 在我的ConfigurationProperties
课程填充之前.如何DataSource
使用Spring Boot快速读取属性并创建bean?
这是我的application.properties的样子:
ds.clients[0]=client1|jdbc:db2://server/client1
ds.clients[1]=client2,client3|jdbc:db2://server/client2
ds.clients[2]=client4|jdbc:db2://server/client4
ds.clients[3]=client5|jdbc:db2://server/client5
Run Code Online (Sandbox Code Playgroud)
我的ConfigurationProperties类:
@Component
@ConfigurationProperties(prefix = "ds")
public class DataSourceSettings {
public static Map<String, String> CLIENT_DATASOURCES = new LinkedHashMap<>();
private List<String> clients = new ArrayList<>();
public List<String> getClients() {
return clients;
}
public void setClients(List<String> clients) {
this.clients = clients;
}
@PostConstruct
public void configure() {
for (String client : clients) {
// extract client name
String[] parts …
Run Code Online (Sandbox Code Playgroud) 如何为findBy
下面的查询获取Spring DATA JPA方法(如....):
Select * from USER where '2016-02-15' between VALID_FROM and VALID_TO;
Run Code Online (Sandbox Code Playgroud) 我注意到在 Spring-boot 中很多人创建模型/实体并实现Serialiazable
接口。
public class ModelBase implements Serializable
Run Code Online (Sandbox Code Playgroud)
我理解序列化数据/类的含义,因为它使您能够保存类的状态(如果我没记错的话,例如保存到文件中)。
但我相信只有在必要时才应该这样做,但无论哪种方式,人们似乎只是倾向于实现该接口。
难道还有什么不同的原因吗?
我是使用SOAP API的新手
我有一个来自API的肥皂响应
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<LoginResponse xmlns="http://test.org/ADMail_Service">
<LoginResult>
<ErrorMessage>Successful login</ErrorMessage>
<Status>true</Status>
</LoginResult>
</LoginResponse>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其转换为对象。
通过在线阅读文章,我尝试使用JAXB来执行此操作,但是我的对象为空。
这是读取响应的代码。我将响应写到xml文件中以进行测试:
try {
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml"));
xsr.nextTag(); // Advance to Envelope tag
xsr.nextTag(); // Advance to Body tag
xsr.nextTag();
xsr.nextTag();
JAXBContext jc = JAXBContext.newInstance(LoginResult.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<LoginResult> je = unmarshaller.unmarshal(xsr, LoginResult.class);
System.out.println(je.getName());
System.out.println(je.getValue());
} catch (XMLStreamException e) {
e.printStackTrace();
} catch (JAXBException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
本LoginResult …
我有一个按钮.onClick按钮触发JS函数.在第一行代码中的这个函数中,我使用jQuery更改了按钮的HTML.然后该功能需要几秒钟.按钮HTML仅在完成功能完成后更改(在浏览器中).
https://jsfiddle.net/wqps1r0k/
代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<button class="btn btn-primary" onclick="setToDisabled(this)">Toggle</button>
<script type="text/javascript">
function setToDisabled(btn) {
//log
console.log('start');
//how to force the browser to show this text immediately?
$(btn).html("TEXT CHANGED ON START OF FUNCTION");
//create a 2 seconds delay
var d1 = new Date();
var t1 = d1.getTime();
var keeprunning = true;
while(keeprunning) {
var d2 = new Date();
var t2 = d2.getTime();
var dif = t2 - t1;
if((dif / 1000) > 2) keeprunning = false;
}
//log
console.log('done');
}
</script> …
Run Code Online (Sandbox Code Playgroud)java ×3
spring ×3
spring-boot ×2
html ×1
javascript ×1
jaxb ×1
jpa ×1
jquery ×1
soap ×1
spring-data ×1
xml ×1