我在Spring的任务调度程序中安排了几个任务:
<task:scheduled-tasks>
<task:scheduled ref="task1" method="run"
cron="0 0 */0 * * *" />
<task:scheduled ref="task2" method="run"
cron="0 0 */30 * * *" />
</task:scheduled-tasks>
<task:scheduler id="scheduler" pool-size="10" />
Run Code Online (Sandbox Code Playgroud)
如何从应用程序上下文中访问计划任务列表并检索元信息(例如下一个执行时间)?
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler)context.getBean("scheduler");
//... how to continue from here?
Run Code Online (Sandbox Code Playgroud) 我特别对Spring和Spring-Batch很新.我还是设法安装了Spring Batch-Admin.我添加了自定义作业和Hibernate/JPA以实现持久性.
一切都按预期工作,直到第一个块应该持久化.然后我收到以下错误消息:
org.springframework.transaction.CannotCreateTransactionException:
Could not open JPA EntityManager for transaction;
nested exception is java.lang.IllegalStateException: Already value
[org.springframework.jdbc.datasource.ConnectionHolder@60d31437]
for key [org.springframework.jdbc.datasource.DriverManagerDataSource@12da4b19]
bound to thread [jobLauncherTaskExecutor-1]
Run Code Online (Sandbox Code Playgroud)
这是完整的堆栈跟踪:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@43f9e588] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@84f171a] bound to thread [jobLauncherTaskExecutor-1]
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy41.saveIfUnique(Unknown Source)
at com.qompa.batch.ArticleItemWriter.write(ArticleItemWriter.java:28)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:171)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:150)
at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor$3.doWithRetry(FaultTolerantChunkProcessor.java:313)
at org.springframework.batch.retry.support.RetryTemplate.doExecute(RetryTemplate.java:240)
at …Run Code Online (Sandbox Code Playgroud) 有一个数组[10,20],我想知道它是否是数组[20,30,10]的子集?
例子:
[10,20] and [30,20,10] - yes
[10,20] and [10,30] - no
[10,20] and [20,10] - yes
[10,20] and [10,20] - yes
Run Code Online (Sandbox Code Playgroud) 我想导入所有属性文件,结束于.properties那个包含在我的项目所有 jar依赖项的src/main/resource位置.
我写了一个JUnit测试,其中我的context.xml位于src/test/resources文件夹中.我使用通配符指定了property-placeholder,但它不起作用.
<context:property-placeholder location="classpath*:*.properties"/>
Run Code Online (Sandbox Code Playgroud)
可能我是愚蠢的,但我无法在网上找到我的问题的解决方案.这里有没有人知道什么是正确的语法?
编辑:
根项目,具有maven依赖项,从我的工作区解析:

我想导入依赖项目的module.properties文件:

假设我有一个Hibernate/JPA实体,如下所示:
@Entity
public class FooEntity {
...
@Type(type = "hstore")
HashMap<String, String> tags;
}
Run Code Online (Sandbox Code Playgroud)
...而hstoreType是此资源的简单UserType实现.
有没有办法在类似于这个Pseudocode的JPQL查询中访问hstore:
SELECT f FROM FooEntity f WHERE f.tags CONTAINS KEY(:key)
Run Code Online (Sandbox Code Playgroud) 所以这是一个初学者的问题.
从使用urls章节执行示例代码时,它会抛出:
线程"main" java.net.SocketException中的异常:java.net.SocketInputStream.read中的连接重置 (SocketInputStream.java:189)...
Origin是openStream()方法.
这是代码:
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道有关于该主题的类似线程,但我找不到适合我的答案.
到目前为止我尝试过的:
无论我尝试什么,我总是得到同样的错误:30秒左右不会发生任何事情然后它抛出提到的SocketException.
我根本不知道如何继续解决这个问题.有用的是获取有关连接重置前30秒内背景中发生的情况的信息.
那么究竟是什么导致了这种异常呢?
最小的提示可以帮助你!谢谢!
我最近下载了microba datepicker,它附带了三个JAR文件:源代码,已编译的coled和一个用于javadoc的JAR.
我使用netbeans并在我有限的能力范围内尝试了所有内容以获取对该文档的访问权限,但是无法成功...你能帮助我解决这个问题吗?
我正在推送配置了 3g 内存的批处理应用程序,
applications:
- name: batch-app
memory: 3G
services:
- scheduler
buildpack: java_buildpack
Run Code Online (Sandbox Code Playgroud)
为批处理应用程序创建作业
cf create-job batch-app job-name ".java-buildpack/open_jdk_jre/bin/java org.springframework.boot.loader.JarLauncher"
Run Code Online (Sandbox Code Playgroud)
然后按如下方式安排作业:
cf schedule-job job-name "30 * ? * *"
Run Code Online (Sandbox Code Playgroud)
现在,每个计划的作业执行都会失败,并出现以下错误:
2018-10-20 [APP/TASK/612f1b80] [OUT] Exit status 137 (out of memory)
Run Code Online (Sandbox Code Playgroud)
同一个作业作为任务运行时会成功(即使内存少于清单中指定的内存):
cf run-task job-name ".java-buildpack/open_jdk_jre/bin/java org.springframework.boot.loader.JarLauncher" --name "manual" -m 2GB
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?
我是Spring-Batch的新手,我想知道是否有办法从ItemReader或ItemWriter中访问step-id?
在我的情况下,允许在单个ItemReader实现中基于不同的步骤定义来切换枚举类型.
有谁知道这样做的方法?
在"applicationContext-base.xml"中我添加如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
>
.....
<!-- transaction support-->
<!-- PlatformTransactionMnager -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- enable transaction annotation support -->
<tx:annotation-driven transaction-manager="txManager" />
Run Code Online (Sandbox Code Playgroud)
我想在"控制器"中为一个函数设置一个事务
@Controller
@RequestMapping("/ywdata")
public class YwController extends BaseController{
....
@Transactional(timeout=1)
private void submitNewSXSQ(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception {
...//STEP1 :do some db insert and update STEP1
if(true)
throw new Exception("test …Run Code Online (Sandbox Code Playgroud) 我正在使用spring-boot-starter-web和spring-boot-starter-data-jpa以及spring-batch-admin(版本1.3.0)将现有的Spring-Batch命令行应用程序迁移到webapp.
我尝试配置应用程序,以便它可以使用多个数据库.经过大量的尝试和错误后,我终于遵循了基于JTA的示例stackoverflow.com/questions/22779155/.
但我仍然BeanCreationException一次又一次地面对同样的事情(见帖子末尾的StackTrace).
由于spring-batch-admin集成可能会出现问题?
以下是ServletInitializer的外观:
@Configuration
@EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class,
DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class })
@Import(MainConfiguration.class)
public class BatchAdmin extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(BatchAdmin.class, args);
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
这里是主要的配置类,如在提到的SO文章中所建议的:
@Configuration
@ComponentScan("com.company.*")
@Import({ ServletConfiguration.class, WebappConfiguration.class, Db1Configuration.class,
Db2Configuration.class })
@EnableTransactionManagement
public class MainConfiguration {
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(true);
hibernateJpaVendorAdapter.setGenerateDdl(true);
hibernateJpaVendorAdapter.setDatabase(Database.POSTGRESQL);
hibernateJpaVendorAdapter.setDatabasePlatform(MyPGDialect.class.getName());
return hibernateJpaVendorAdapter;
}
@Bean(name = "userTransaction")
public UserTransaction userTransaction() throws Throwable {
UserTransactionImp userTransactionImp = new …Run Code Online (Sandbox Code Playgroud) spring spring-mvc spring-batch-admin spring-data-jpa spring-boot
我很难配置我的Spring Boot应用程序以通过Spring-Cloud-Connectors连接到提供Config-Server的PWS(Pivotal Web Services).
在manifest.yml中,配置服务器绑定到应用程序,相应的VCAP_SERVICES条目正确反映了该应用程序:
applications:
- name: edge-service-webapp-myapp
services:
- infrastructure-config-server
memory: 512M
env:
TRUST_CERTS: api.run.pivotal.io
SPRING_PROFILES_DEFAULT: cloud
instances: 1
host: edge-service-webapp-myapp
domain: cfapps.io
buildpack: java_buildpack
{
"VCAP_SERVICES": {
"p-config-server": [
{
"credentials": {
"access_token_uri": "https://p-spring-cloud-services.uaa.run.pivotal.io/oauth/token",
"client_id": "p-config-server-84d66ea6-ebc6-xxx",
"client_secret": "***",
"uri": "https://config-b4320676-xxx.cfapps.io"
}, ...
}
Run Code Online (Sandbox Code Playgroud)
该应用程序使用spring-boot-starter-parent 1.5.2.RELEASE,spring-cloud-dependencies Camden.SR5和spring-cloud-services-dependencies 1.4.1.RELEASE构建.此外,我使用spring-cloud-starter-config和spring-boot-starter-cloud-connectors作为显式依赖项.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-dependencies</artifactId>
<version>1.4.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
....
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId> …Run Code Online (Sandbox Code Playgroud) spring cloud-foundry spring-boot spring-cloud pivotal-cloud-foundry
在德国汉诺威参观CeBit IT-fair时,我遇到了两三个基于Eclipse GUI的应用程序(例如 Talend Open Studio).有没有人知道Eclipse GUI是否可供公众使用,如果是,如何获得最简单的访问权限?
先感谢您!
java ×7
spring ×7
hibernate ×2
jpa ×2
postgresql ×2
spring-batch ×2
spring-boot ×2
arrays ×1
datepicker ×1
eclipse ×1
exception ×1
hstore ×1
mybatis ×1
netbeans ×1
spring-cloud ×1
spring-mvc ×1
sql ×1