GVKun编程网logo

如何在Spring Boot中以编程方式向/ info端点添加内容?(spring boot怎么写接口)

23

对于如何在SpringBoot中以编程方式向/info端点添加内容?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍springboot怎么写接口,并为您提供关于asp.net–如何在页面加载中

对于如何在Spring Boot中以编程方式向/ info端点添加内容?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍spring boot怎么写接口,并为您提供关于asp.net – 如何在页面加载中以编程方式向页面添加控件?、ios – 如何在Swift中以编程方式创建约束?、java – Spring Boot Actuator – 无法禁用/ info端点、java – 以编程方式在springboot中设置hibernate.ddl-auto的有用信息。

本文目录一览:

如何在Spring Boot中以编程方式向/ info端点添加内容?(spring boot怎么写接口)

如何在Spring Boot中以编程方式向/ info端点添加内容?(spring boot怎么写接口)

如何/info在Spring Boot中以编程方式向终端添加内容?该文档指出,/health通过使用HealthIndicator接口,这对于端点是可能的。/info端点也有东西吗?

我想在那里添加操作系统名称和版本以及其他运行时信息。

答案1

小编典典

在Spring Boot 1.4中,您可以声明InfoContributerbean来简化此过程:

@Componentpublic class ExampleInfoContributor implements InfoContributor {    @Override    public void contribute(Info.Builder builder) {        builder.withDetail("example",                Collections.singletonMap("key", "value"));    }}

有关更多信息,请参见http://docs.spring.io/spring-
boot/docs/1.4.0.RELEASE/reference/htmlsingle/#production-ready-application-
info-custom。

asp.net – 如何在页面加载中以编程方式向页面添加控件?

asp.net – 如何在页面加载中以编程方式向页面添加控件?

我试图从页面加载阶段后面的代码添加控件到页面,如下所示:
foreach (FileInfo fi in dirInfo.GetFiles())
{
    HyperLink hl = new HyperLink();
    hl.ID = "Hyperlink" + i++;
    hl.Text = fi.Name;
    hl.NavigateUrl = "../downloading.aspx?file=" + fi.Name + "&user=" + userIdpar;
    Page.Controls.Add(hl);
    Page.Controls.Add(new LiteralControl("<br/>")); 
}

我得到的错误是在Page.Controls.Add(hl)上,这里是解释:

The control collection cannot be modified during DataBind,Init,Load,PreRender or Unload phases.

我该怎么做才能解决这个问题?提前致谢.

解决方法

创建自己的容器集合并将其添加到它,而不是直接添加到页面控件集合.

在.aspx上:

<asp:Panel id="links" runat="server" />

在后面的代码中(我建议使用Init事件处理程序而不是页面加载):

foreach (FileInfo fi in dirInfo.GetFiles())
{
  HyperLink hl = new HyperLink();
  hl.ID = "Hyperlink" + i++;
  hl.Text = fi.Name;
  hl.NavigateUrl = "../downloading.aspx?file=" + fi.Name + "&user=" + userIdpar;
  links.Controls.Add(hl);
  links.Controls.Add(new LiteralControl("<br/>"));
}

ios – 如何在Swift中以编程方式创建约束?

ios – 如何在Swift中以编程方式创建约束?

我正在尝试使用以下代码设置UIButton的宽度:
constraintButtonPlayWidth = NSLayoutConstraint(item: buttonPlay,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: self.view,multiplier: 1,constant: 100)
self.view.addConstraint(constraintButtonPlayWidth)

但按钮拉得太大了;可能是因为toItem:self.view.我尝试修改约束的常量,但这并没有改变任何东西.

如何正确设置此约束,使其实际宽度为100?

解决方法

你很亲密约束只应该有一个项目,因为它不是相对于另一个项目.
constraintButtonPlayWidth = NSLayoutConstraint (item: buttonPlay,toItem: nil,attribute: NSLayoutAttribute.NotAnAttribute,constant: 100)
self.view.addConstraint(constraintButtonPlayWidth)

java – Spring Boot Actuator – 无法禁用/ info端点

java – Spring Boot Actuator – 无法禁用/ info端点

我尝试在application.yml配置文件中禁用生产环境的所有执行器端点:
endpoints.enabled: false

它适用于除/ info之外的所有端点.
如何关闭给定环境的所有端点?

更新:

我正在做的项目也是Eureka的客户.
在状态页面和健康指标(http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html)部分的Spring Cloud Netflix文档中,它表示“Eureka实例默认为”/ info“和”/ health“.

是否有任何解决方案来禁用这些端点?

我能够使用endpoints.enabled:false禁用/ health端点,但不能使用/ info端点.

解决方法

最后我设法解决了我的问题.我在执行器中只启用了/ info和/ health端点.并且只允许具有角色ADMIN的用户访问/ info端点我需要混合执行器管理安全性和弹簧安全配置.

所以我的application.yml看起来像这样:

endpoints.enabled: false

endpoints:
    info.enabled: true
    health.enabled: true

management.security.role: ADMIN

像这样的spring安全配置(我需要将ManagementSecurityConfig的顺序更改为具有更高优先级):

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {


    @Configuration
    protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

        @Autowired
        private AuthenticationProvider authenticationProvider;

        public AuthenticationSecurity() {
            super();
        }

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
             auth.inMemoryAuthentication().withUser("admin").password("secret").roles("ADMIN");
        }
    }

    @Configuration
    @Order(Ordered.HIGHEST_PRECEDENCE + 2)
    public static class ManagementSecurityConfig extends WebSecurityConfigurerAdapter {


        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable()
                    .requestMatchers()
                    .antMatchers("/info/**")
                    .and()
                    .authorizeRequests()
                    .anyRequest().hasRole("ADMIN")
                    .and()
                    .httpBasic();
        }
    }

    @Configuration
    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

        protected void configure(HttpSecurity http) throws Exception {
            // API security configuration
        }

    }
}

java – 以编程方式在springboot中设置hibernate.ddl-auto

java – 以编程方式在springboot中设置hibernate.ddl-auto

我在非Web应用程序和数据jpa中使用 springboot.我使用除数据源之外的默认配置:

private static final String dataSourceUrl = "jdbc:h2:./Database;DB_CLOSE_ON_EXIT=FALSE";
@Bean
public DataSource dataSource() {
    return DataSourceBuilder.create().url(dataSourceUrl).username("user").password("pwd").build();
}

如何以编程方式设置spring.jpa.hibernate.ddl-auto属性?

解决方法

添加以下bean似乎可以完成这项工作(感谢Jens的评论):

@Bean
  public LocalContainerEntityManagerfactorybean entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerfactorybean em = new LocalContainerEntityManagerfactorybean();
    em.setDataSource(dataSource);
    em.setPackagesToScan(new String[] { "packages.to.scan" });

    JpavendorAdapter vendorAdapter = new HibernateJpavendorAdapter();
    em.setJpavendorAdapter(vendorAdapter);

    Properties properties = new Properties();
    properties.setProperty("hibernate.dialect","org.hibernate.dialect.H2Dialect");
    properties.setProperty("hibernate.hbm2ddl.auto","update");
    em.setJpaProperties(properties);

    return em;
  }

我们今天的关于如何在Spring Boot中以编程方式向/ info端点添加内容?spring boot怎么写接口的分享就到这里,谢谢您的阅读,如果想了解更多关于asp.net – 如何在页面加载中以编程方式向页面添加控件?、ios – 如何在Swift中以编程方式创建约束?、java – Spring Boot Actuator – 无法禁用/ info端点、java – 以编程方式在springboot中设置hibernate.ddl-auto的相关信息,可以在本站进行搜索。

本文标签: