小编mic*_*ldo的帖子

@ImportAutoConfiguration和@Import有什么区别

是否真的org.springframework.boot.autoconfigure.ImportAutoConfiguration是改进替换org.springframework.context.annotation.Import因为同样和另外尊重

@AutoConfigureBefore,@AutoConfigureAfter@AutoConfigureOrder

spring-boot spring-java-config

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

如何使用java.time从年份和星期解析字符串中的日期

在旧的Java中,我可以这样做:

System.out.println(new SimpleDateFormat("yyyy w", Locale.UK).parse("2015 1"));
// shows Mon Dec 29 00:00:00 CET 2014

System.out.println(new SimpleDateFormat("yyyy w", Locale.US).parse("2015 1"));
// shows Mon Dec 28 00:00:00 CET 2014
Run Code Online (Sandbox Code Playgroud)

我想在Java 8中使用java.time.

System.out.println( LocalDate.parse("2015 1", DateTimeFormatter.ofPattern("yyyy w", Locale.US)));
Run Code Online (Sandbox Code Playgroud)

结果:

java.time.format.DateTimeParseException:无法解析文本'2015 1':无法从TemporalAccessor获取LocalDate:{WeekOfWeekBasedYear [WeekFields [SUNDAY,1]] = 1,Year = 2015},ISO类型为java.time. format.Parsed

如何在java.time中做到这一点?

此外,我不满意我必须通过Locale来确定一周的第一天:星期一和星期天.它不是乡村功能,而是日历功能.我想使用像java.time.temporal.WeekFields.ISO这样的东西来显示周从星期一开始的世界

我发现了类似的情况:https://stackoverflow.com/questions/3941700/how-to-get-dates-of-a-week-i-know-week-number

但不适用于Java 8中的java.time.此外,首先创建日期对象并稍后设置正确周的解决方案并不优雅.我想一次创建最终日期.

java java-time

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

在 git push 我得到错误:错误:无效的协议:想要'旧的新参考'

我有分支 x。我打字git push origin x:y

我收到错误信息

error: error: invalid protocol: wanted 'old new ref'
fatal: internal server error
fatal: The remote end hung up unexpectedly
Counting objects: 140, done.
Run Code Online (Sandbox Code Playgroud)

也许这很重要:当我克隆存储库时,为了性能我使用了开关

-b master --single-branch
Run Code Online (Sandbox Code Playgroud)

git 版本 2.6.2.windows.1

gerrit 版本 2.9.4

git git-push gerrit

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

JMSTemplate 中的 setSessionTransacted 到底意味着什么?

如果我正确理解 Spring 文档,请解释一下。

Spring 文档指出:https ://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jms-tx

(...)当您在非托管环境中使用 JmsTemplate 时,您可以通过使用属性 sessionTransacted 和 sessionAcknowledgeMode 来指定这些值(事务和确认模式)。

当您将 PlatformTransactionManager 与 JmsTemplate 一起使用时,模板始终会获得一个事务性 JMS 会话。(..)

(顺便说一句,这是真的 - 会话是事务性的)

Javadoc指出: https: //docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jms/core/JmsTemplate.html

JMS 会话的默认设置是“不进行事务处理”和“自动确认”。根据 Java EE 规范的定义,当在活动事务中创建 JMS 会话时,无论是 JTA 事务还是Spring 管理的事务,事务和确认参数都将被忽略。

我知道,如果事务处于活动状态,JMS 模板会话事务设置将被忽略 -这是正确的- 并且会话应该参与活动事务 -这是不正确的

我调试为什么它不正确,我发现: https: //github.com/spring-projects/spring-framework/blame/master/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils .java#L353

if (resourceHolderToUse != resourceHolder) {
  TransactionSynchronizationManager.registerSynchronization(
    new JmsResourceSynchronization(resourceHolderToUse, connectionFactory,
                             
 resourceFactory.isSynchedLocalTransactionAllowed()));
 resourceHolderToUse.setSynchronizedWithTransaction(true);
 TransactionSynchronizationManager.bindResource(connectionFactory, resourceHolderToUse);
}
Run Code Online (Sandbox Code Playgroud)

该线resourceHolderToUse.setSynchronizedWithTransaction(true)与文档对齐。

这里的问题是:resourceFactory.isSynchedLocalTransactionAllowed()

因为resourceFactoryorg.springframework.jms.core.JmsTemplate.JmsTemplateResourceFactory#isSyncchedLocalTransactionAllowed 指向JmsTemplate#sessionTransacted.

结论:根据文档,如果事务处于活动状态,JmsTemplate#sessionTransacted …

spring transactions jmstemplate spring-transactions spring-jms

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

当mojo从不同模块扩展mojo时,自定义maven插件失败(没有AbstractMojo)

我有两个maven插件模块mutli项目:base和child(<packaging>maven-plugin</packaging>).孩子依靠基地.

基本插件有单个类:

public abstract class BaseMojo extends AbstractMojo {}
Run Code Online (Sandbox Code Playgroud)

与POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>plugin-set</groupId>
        <artifactId>plugin-set</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>plugin-base</artifactId>
    <packaging>maven-plugin</packaging>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>3.3.3</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.4</version>
                <configuration>
                    <goalPrefix>my</goalPrefix>
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>
                <executions>
                    <execution>
                        <id>mojo-descriptor</id>
                        <goals>
                            <goal>descriptor</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

子插件有单一类:

public abstract class ChildMojo extends BaseMojo {}
Run Code Online (Sandbox Code Playgroud)

与POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>plugin-set</groupId>
        <artifactId>plugin-set</artifactId>
        <version>0.0.1-SNAPSHOT</version> …
Run Code Online (Sandbox Code Playgroud)

maven-plugin maven

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

不为可执行WAR调用SpringBootServletInitializer#configure

我想将war应用程序迁移到Spring引导应用程序。

我按照http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#howto-convert-an-existing-application-to-spring-boot的说明进行操作,并制作了类

@EnableAutoConfiguration
public class MyInitializer extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    application.banner(new MyBanner());
    application.sources(MyEndpoint.class);
    return application;
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到了可部署的WAR。

在下一阶段,我想获取可执行的WAR。我上课了

public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyInitializer.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

问题是当我调用java -jar target/myapp.warMyInitializer#configure时未执行

我有点困惑。如何避免从MyInitializer到MyApplication的复制粘贴逻辑。我必须将这些课程合为一体吗?

spring-boot

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