通过/ info执行器端点的Spring Boot构建信息

时间:2018-08-13 01:24:54

标签: spring-boot gradle spring-boot-actuator

在Spring Boot应用程序中,我想通过buildInfo()插件任务中的springBootbuild-info.properties执行器端点中获取构建和其他与应用程序相关的信息。但是,构建信息属性文件名不是{app_name}.properties,而是不同的/META-INF/{app_name}.properties。该属性文件存在于Spring Boot创建的胖罐子中的springBoot { buildInfo() } 中。

import numpy as np
import tensorflow as tf

n_inputs = 2
n_hidden = 3
n_outputs = 1

X = tf.placeholder(tf.float32, shape=(None, n_inputs), name='X')
y = tf.placeholder(tf.float32, shape=(None), name='y')

def neuron_layer(X, n_neurons, name, activation=None):
    with tf.name_scope(name):
        n_inputs = int(X.get_shape()[1])
        stddev = 2 / np.sqrt(n_inputs)
        init = tf.truncated_normal((n_inputs, n_neurons), stddev=stddev)
        W = tf.Variable(init, name="weights")
        b = tf.Variable(tf.zeros([n_neurons]), name="bias")
        Z = tf.matmul(X, W) + b
        if activation is not None:
            return activation(Z)
        else: return Z

with tf.name_scope('nn'):
    hidden = neuron_layer(X, n_hidden, name='hidden', activation=tf.nn.sigmoid)
    prediction_probabilities = neuron_layer(hidden, n_outputs, name='outputs', activation=tf.nn.sigmoid)

with tf.name_scope('loss'):
    mse_loss = tf.reduce_mean(tf.squared_difference(y, prediction_probabilities), name='loss')    

learning_rate = 0.1

with tf.name_scope('train'):
    optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
    training_op = optimizer.minimize(mse_loss)

with tf.name_scope('eval'):
    correct = tf.equal(tf.greater_equal(prediction_probabilities,0.5), tf.cast(y,tf.bool))
    accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))

init = tf.global_variables_initializer()

X_train = [
    (0, 0),
    (0, 1),
    (1, 0),
    (1, 1)
]
y_train = [0,1,1,0]

with tf.Session() as sess:
    init.run()
    for epoch in range(500):
        _, mse, acc = sess.run([training_op, mse_loss, accuracy], 
                               feed_dict={X: np.array(X_train), y: np.array(y_train)})
        print("mse: %.4f, accuracy: %.2f" % (mse, acc))

我的问题是:有什么方法可以在任务中配置属性文件名而不是采用默认值?

更新

enter image description here

1 个答案:

答案 0 :(得分:1)

您误解了buildInfo的工作方式。 actuator端点使用build-info.properties中的/META-INF/文件。 buildInfo配置在运行时不起作用,实际上在运行时没有任何限制(例如,当您的应用程序在生产环境中运行时)。

buildInfo()向您的gradle构建中添加了一个任务,该任务可以在构建应用程序期间基于build-info.properties文件中的属性生成{app_name}.properties。假设您已经拥有它,则需要按照documentation中所述在构建过程中运行它:

  

这将配置名为bootBuildInfo的BuildInfo任务,如果配置,   存在,使Java插件的class任务依赖于它