小编Ale*_*Zai的帖子

Laravel 5加载基于.env.master的env文件?

我正在计划做类似的事情,通过在.env.master中创建变量来指定在应用程序引导期间加载的env文件,例如ENV_VER = dev.env

这是因为我有几个分支,例如development,release-1.1等.因此,通过根据主env文件中指定的名称加载env文件,开发人员不再需要将新变量复制并粘贴到其本地副本中.相反,只需指定要在主env文件中加载的env文件的版本.顺便说一句,我有几个env文件,如dev.env,1.6.env等.

可能吗?

php laravel

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

Spring Batch JpaItemWriter vs HibernateItemWriter 以及为什么在使用 HibernateItemWriter 时需要 HibernateTransactionManager

我正在使用 Spring Boot 项目处理 Spring Batch。我的问题是,当我如下使用 HibernateItemWriter 时,为什么需要来自 LocalSessionFactoryBean 的 HibernateTransactionManager 和 SessionFactory?

应用程序.java

import java.util.Properties;
import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
import org.springframework.transaction.PlatformTransactionManager;

@SpringBootApplication
@EnableBatchProcessing
public class Application {

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

@Bean
public PlatformTransactionManager transactionManager() {
    HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    transactionManager.setSessionFactory(sessionFactory(null));
    return transactionManager;
}

@Bean
public SessionFactory sessionFactory(DataSource datasource) {
    Properties properties = new Properties();
    properties.setProperty("hibernate.show_sql", "true");
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-batch spring-boot

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

Quartz 作业不参与 Spring 托管事务(Quartz + Spring Batch Boot)

如果在 Spring Batch 中触发作业执行,我有几个 Spring Batch 作业可以正常工作。这些作业将使用 JpaItemWriter 读取和写入数据库,其中需要事务。

我的问题是,我有配置为定期运行这些作业的石英调度程序,我收到“javax.persistence.TransactionRequiredException: no transaction is in progress”错误。我知道目前石英正在实例化作业 bean 而不是 spring 本身,这使得 bean 不知道 spring 管理的正在进行的事务,如果我错了,请纠正我。

但是,我尝试了很多方法,但都没有奏效。以下是我目前的配置:

石英属性

org.quartz.scheduler.instanceName=sample_instance
org.quartz.scheduler.instanceId=AUTO
org.quartz.threadPool.threadCount=5

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.MSSQLDelegate
org.quartz.jobStore.useProperties=true
org.quartz.jobStore.misfireThreshold=60000
org.quartz.jobStore.tablePrefix=QRTZ_

org.quartz.jobStore.isClustered=true
org.quartz.jobStore.clusterCheckinInterval=20000
Run Code Online (Sandbox Code Playgroud)

调度程序配置文件

@EnableScheduling
@Configuration
public class SchedulerConfig {

@Inject
private DataSource dataSource;

@Inject
private JobsListenerService jobsListenerService;

@Bean
public JobFactory jobFactory(ApplicationContext applicationContext) {
    AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
    jobFactory.setApplicationContext(applicationContext);
    return jobFactory;
}


@Bean
public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory)
        throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setJobFactory(jobFactory);
    factory.setDataSource(dataSource); …
Run Code Online (Sandbox Code Playgroud)

quartz-scheduler spring-batch spring-boot

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