小编Cre*_*mbo的帖子

以编程方式重新启动Spring Boot应用程序/刷新Spring Context

我试图以编程方式重新启动我的Spring应用程序,而无需用户进行干预.

基本上,我有一个页面,允许切换应用程序的模式(实际上意味着切换当前活动的配置文件),据我所知,我必须重新启动上下文.

目前我的代码非常简单,它仅用于重启位(顺便说一下,这是Kotlin):

    context.close()
    application.setEnvironment(context.environment)
    ClassUtils.overrideThreadContextClassLoader(application.javaClass.classLoader)
    context = application.run(*argsArray)
Run Code Online (Sandbox Code Playgroud)

但是,我现在context.close()就立即存在JVM.我也试过了,context.refresh()但这似乎只是简单地杀死了Tomcat/Jetty(只是为了防止这是一个Tomcat问题)然后没有任何反应.

我也看过以编程方式重新启动Spring Boot应用程序,但似乎没有任何东西可以帮助我解决这些问题.此外,我查看了Spring Actuator,它应该具有/restart端点,但似乎不再存在了?

非常感谢帮助.谢谢.

java spring spring-mvc kotlin spring-boot

9
推荐指数
4
解决办法
2万
查看次数

由于新的HashSet,Spring Hibernate StaleObjectStateException?

我的代码在很长一段时间内工作得很好,但经过几次重构之后,我注意到我突然无法再保存一个Group对象了.

我遇到了可怕的Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)错误.谷歌搜索之后当然我发现了这个StackOverflow问题,但它根本没有帮助我,因为我没有同时做任何事情.

经过我的重构后,我发现的唯一区别就是这种变化.

之前:

    final Collection<Sample> allByBarcode = sampleService.byBarcode(groupRequest.getSamples(), currentUser);

    if (!allByBarcode.isEmpty()) {
        Group group = new Group();

        group.setName(groupRequest.getName());
        group.setSamples(allByBarcode);
        group.setType(groupRequest.getType());
        group.setOwner(currentUser);

        group = repository.save(group);

        return Optional.ofNullable(group);
    }
Run Code Online (Sandbox Code Playgroud)

重构后(不记得具体原因)它成了:

    final Collection<Sample> allByBarcode = sampleService.byBarcode(groupRequest.getSamples(), currentUser);

    if (!allByBarcode.isEmpty()) {
        Group group = new Group();

        group.setName(groupRequest.getName());
        group.setSamples(new HashSet<>(allByBarcode));
        group.setType(groupRequest.getType());
        group.setOwner(currentUser);

        group = repository.save(group);

        return Optional.ofNullable(group);
    }
Run Code Online (Sandbox Code Playgroud)

将它改回原来后,它每次都突然重新开始工作,没有任何错误.

任何人都可以解释这个错误的原因是什么,因为这实际上是代码中唯一的区别使它再次起作用?

更新1:

我尝试了另一种变体:

Group group = new …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate

8
推荐指数
1
解决办法
1410
查看次数

mysql LIMIT和PDO的问题

尝试使用PDO进行可怕的分页,但我找不到符合我情况的答案:

    $pageVar = 10;
    $startRowLimit = ($page * $pageVar) - $pageVar; // returns correct value 

$articlesQuery = "SELECT 
`ID`,`Title`,`Text`,`Poster`,`Date`,
( SELECT `ID` FROM users WHERE article.`Poster` = users.`Username` )
FROM article WHERE `Visible` = 1 ORDER BY `Date` DESC LIMIT ? , ? ";

$articles = $mysqli->selectAll($articlesQuery, array($startRowLimit, $pageVar));
Run Code Online (Sandbox Code Playgroud)

这是selectAll函数:

        public function selectAll($query, $params){

        $this->sql = $this->dbh->prepare($query);
        $this->sql->execute($params);
        $result = $this->sql->fetchAll(PDO::FETCH_ASSOC);

        return $result;

    }
Run Code Online (Sandbox Code Playgroud)

我怎样才能使它工作?我试过了

array((int) $startRowLimit, (int) $pageVar)
Run Code Online (Sandbox Code Playgroud)

但这不起作用.任何的想法?

php mysql pdo

5
推荐指数
1
解决办法
6523
查看次数

不能在同一个Python文件中"定义"两个数据库?

我刚刚开始学习Python,我正在慢慢掌握它,但我遇到了一个问题.

我正在尝试使用Google的App Launcher SDK创建一个包含文章的简单网站.

现在,当我在Google网站上关注小指南时一切正常,但现在我想创建另一个数据库:

class Articles(db.Model):
    title = db.TextProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

这里没有错误.然后我尝试进行查询,获取所有信息并将其发布到模板中:

class Articles(webapp.RequestHandler):
    def get(self):
        articles_query = Articles.all().order('-date')
        articles = articles_query.fetch(10)

        template_values = {'articles': articles}

        path = os.path.join(os.path.dirname(__file__), 'articles.html')
        self.response.out.write(template.render(path, template_values)) 
Run Code Online (Sandbox Code Playgroud)

在这里我收到一个错误:

line 45, in get
    articles_query = Articles.all().order('-date')
AttributeError: type object 'Articles' has no attribute 'all'
Run Code Online (Sandbox Code Playgroud)

我基本上从谷歌的教程中复制了查询,只是更改变量,但它不起作用.

有任何想法吗?

python google-app-engine

1
推荐指数
1
解决办法
92
查看次数