小编Nar*_*rma的帖子

Java示例:使用Quartz进行动态作业调度

我想公开一个用户界面来动态定义Quartz JOB.用户应该具有定义JOB属性的工具,例如JOB名称,cron表达式或时间间隔,任务等的特定java类.

是否有任何开源可以促进此功能?或者,如果我想为动态Quartz Scheduler创建自己的模块,那么应该采用什么方式呢?

spring quartz-scheduler

23
推荐指数
2
解决办法
6万
查看次数

Eclipse Blue,Maven:项目配置与pom.xml不同步

我在我的开发环境中使用Eclipse Blue 10和Maven 3.

我通常按​​照以下路径从SVN导入maven项目:

File > Import> SVN > Checkout Projects from SVN 
Run Code Online (Sandbox Code Playgroud)

然后导入所有maven项目:

Right click on imported project > Maven4MyEclipse> Existing Maven Projects
Run Code Online (Sandbox Code Playgroud)

我有一个名为'project-ear'的maven模块,这个模块是将我的所有Web应用程序绑定到一个耳中.

但每当我将EAR模块导入为eclipse项目时,eclipse会在"Problems"选项卡中提示以下错误:

项目配置与pom.xml不是最新的.运行项目配置更新.

如何解决这个问题?我没有看到任何"运行项目配置更新"的方法.

请帮忙.

EAR模块的Pom.xml:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.company.xxx</groupId>
    <artifactId>my</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.company.xxx.ear</groupId>
<artifactId>my-ear</artifactId>
<packaging>ear</packaging>
<name>my-ear</name>

<build>
    <finalName>web-app</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <modules>
                    <webModule>
                        <groupId>com.company.xxx.myweb</groupId>
                        <artifactId>my-web</artifactId>
                        <contextRoot>/txcs</contextRoot>
                    </webModule>                        
                </modules>
                <generateApplicationXml>true</generateApplicationXml>
                <displayName>web-app</displayName>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>com.company.xxx.myweb</groupId>
        <artifactId>my-web</artifactId>
        <type>war</type>
        <version>${project.version}</version>
    </dependency>       
</dependencies>
Run Code Online (Sandbox Code Playgroud)

eclipse ear maven

22
推荐指数
2
解决办法
6万
查看次数

JPA2.0/Hibernate:为什么JPA会激活查询以更新所有列值,甚至托管bean的某些状态也会更改?

我正在使用JPA2.0和Hibernate.

例如,我有下表的JPA实体:

User [userId, userName, userAddress]
Run Code Online (Sandbox Code Playgroud)

我可以使用find()方法获取用户实体:

User user = entityManager.find(User.class , 1L); // 1L is user id
Run Code Online (Sandbox Code Playgroud)

现在,如果我在上面提取的同一个用户实体上更改任何用户的状态(比如说userName):

user.setUserName("Narendra");
Run Code Online (Sandbox Code Playgroud)

并使用merge()方法执行合并:

entityManager.merge(user);
Run Code Online (Sandbox Code Playgroud)

使用JPA/hibernate在合并时触发的以下查询成功执行合并:

Hibernate: update User set USERID =?, USERNAME=?, USERADDRESS=? where USERID=?
Run Code Online (Sandbox Code Playgroud)

在这里我的问题是,如果我在User实体中只更改了用户名状态,我没有更改userId,userAddress等.JPA应该在查询之下(仅更改userName)而不是查询之上.

 Hibernate: update User set USERNAME=? where USERID=?
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

hibernate jpa-2.0

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

Maven:在发布时将SNAPSHOT更改为发布父/子模块版本的最佳方法?

在开发时,我们对maven模块使用SNAPSHOT版本(例如1.0-SNAPSHOT).

例如,父模块的Maven Configugration:

<groupId>com.mycomp.basemodule</groupId>
<artifactId>base-module</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>base-module</name>
<modules>       
    <module>sub-module1</module>        
    <module>sub-module2</module>        
    <module>sub-module3</module>        
    <module>sub-module4</module>        

</modules>
Run Code Online (Sandbox Code Playgroud)

例如Child Module的Maven Configugration:

子模块-1:

<parent>
     <groupId>com.mycomp.basemodule</groupId>
      <artifactId>base-module</artifactId>
      <version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.mycomp.sub-module1</groupId>
<artifactId>sub-module1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>sub-module1</name>
Run Code Online (Sandbox Code Playgroud)

还要考虑其他子模块(2,3,4)的相同配置.

在发布项目/补丁时,我们需要将此SNAPSHOT版本更改为实际发布版本.

有一种粗略的方法可以改变版本.我可以转到父和所有子模块的每个pom.xml,并可以将SNAPSHOT版本更改为发布版本.

有没有其他最佳实践来更改此SNAPSHOT版本以在公共位置发布版本,以便我不需要更新所有pom.xml文件?

maven-3

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

在Hibernate的EmptyInterceptor中注入JPA的实体管理器

我在我的数据访问层使用JPA-2.0和Hibernate.

出于审计日志记录的目的,我通过在persistence.xml中配置下面的属性来使用Hibernate的EmptyInterceptor:

<property name="hibernate.ejb.interceptor"  
                value="com.mycom.audit.AuditLogInterceptor" /> 
Run Code Online (Sandbox Code Playgroud)

AuditLogInterceptor扩展Hibernate的' org.hibernate.EmptyInterceptor '.

public class AuditLogInterceptor extends EmptyInterceptor {  

    private Long userId;  

    public AuditLogInterceptor() {}  

    @Override  
    public boolean onSave(Object entity, Serializable id, Object[] state,  
            String[] propertyNames, Type[] types) throws CallbackException {  
        // Need to perform database operations using JPA entity manager
        return false;  
    }  

   @Override
    public boolean onFlushDirty(Object entity, Serializable id,
            Object[] currentState, Object[] previousState,
            String[] propertyNames, Type[] types) {
        // other code here        
        return false;
    }

    @Override  
    public void postFlush(Iterator iterator) …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa-2.0 audit-logging

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

Spring/JPA/JSF的异常处理策略

我们在我们的应用程序中使用JSF,Spring和JPA.我们正在努力简化我们项目的异常处理策略.

我们的应用程序架构如下:

UI(JSF) - >托管豆 - >服务 - > DAO

我们正在为DAO层使用Exception Translation bean后处理器.这是在Spring Application Context文件中配置的.

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 
Run Code Online (Sandbox Code Playgroud)

Spring将所有数据库异常包装到'org.springframework.dao.DataAccessException'中.我们没有在DAO Layer中进行任何其他异常处理.

我们处理以下异常的策略:

表示层:

Class PresentationManangedBean{

 try{
      serviceMethod();
   }catch(BusinessException be){
      // Mapping exception messages to show on UI
   }
   catch(Exception e){
       // Mapping exception messages to show on UI
   }

}
Run Code Online (Sandbox Code Playgroud)

服务层

@Component("service")
Class Service{

 @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = BusinessException.class)
 public serviceMethod(){

  try{

      daoMethod();

   }catch(DataAccessException cdae){
      throws new BusinessException(); // Our Business/Custom exception
   }
   catch(Exception e){
      throws new …
Run Code Online (Sandbox Code Playgroud)

java spring jpa exception-handling exception

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

TestNG:如何跳过某些测试的 @BeforeMethod 调用

我正在使用 TestNG 进行单元测试。我正在使用@BeforeMethod保存记录,然后执行更新、搜索、删除测试。

我正在寻找可以避免对某些测试用例执行@BeforeMethod方法调用的选项。例如,我有三个测试保存、更新和删除。在这种情况下,我只想调用@BeforeMethod进行更新和删除测试,而不是保存测试。任何想法?

请注意,我不想使用@DependesOnMethods,因为不建议使用它。

提前致谢。

我的测试类如下所示:

@ContextConfiguration("file:application-context-test.xml")
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class MyEntityTest {

    int long myEntityId; 

    @BeforeMethod 
    public saveRecord(){
      session=getCurrentSessionFactory()
      myEntity = new myEntity();
      myEntityId = session.save(myEntity)
    }

    @Test
    public saveTest(){
      session=getCurrentSession()
      myEntity =session.getByID(myEntityId)
      session.save(myEntity)
    }

    @Test
    public updateTest(){
      session=getCurrentSession()
      myEntity =session.getByID(myEntityId)
      session.update(myEntity)
    }
}
Run Code Online (Sandbox Code Playgroud)

java testng unit-testing

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

使用Java API格式化JavaScript

我在java中使用velocity生成JavaScript代码.

例如:我生成了JavaScript并得到了以下字符串:

importClass(java.util.ArrayList); function fun(arg) { if (true){ return true;} else{    return true;}}
Run Code Online (Sandbox Code Playgroud)

是否有任何Java API采用此String并以下面的方式格式化此JavaScript:

importClass(java.util.ArrayList);

function fun(arg) { 
   if (true){ 
       return true;
   }
   else{
    return true;
   } 
}
Run Code Online (Sandbox Code Playgroud)

javascript java velocity

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

由于EHCache导致的内存泄漏问题

我在我的性能环境中面临内存泄漏问题,因为EhCache具有以下configuraiton:

<cache name="mycache"
            maxElementsInMemory="50000"
            eternal="false"
            timeToIdleSeconds="300"
            timeToLiveSeconds="0"
            overflowToDisk="false"
            diskPersistent="false"
            memoryStoreEvictionPolicy="LRU"
            />                
Run Code Online (Sandbox Code Playgroud)

我接受了堆转储并尝试使用IBM Heap Analyzer分析泄漏的原因.IBM Heap分析器怀疑内存泄漏,信息如下:

Leak suspect:   576,690,536 bytes (83.16 %) of Java heap is used by 128 instances of net/sf/ehcache/store/chm/SelectableConcurrentHashMap$Segment
Contains an instance) of the leak suspect: - org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean holding 117,109,616 bytes at 0x1b6fb410

Total size: 576,690,536 bytes

Size:   528 bytes
Run Code Online (Sandbox Code Playgroud)

我的对象(存储在ehcache中)大小为88字节.

有了这些信息,我无法理解在这种情况下可能导致内存泄漏的原因.

我的对象是否未从缓存中刷新/删除?我的ehcache配置中有什么奇怪的东西吗?如果没有从缓存中删除对象,可能是什么原因?

任何的想法?

java memory-leaks ehcache

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

多线程和集群环境中的自定义序列生成

我正在寻找解决自定义序列生成问题的选项.让我通过举个例子来描述我的问题:

比方说,公司和员工表有两个表,

Table: Company
-----------------------------------------------
CompanyId  | CompanyName | LatestSequenceValue
-----------------------------------------------
    c1     |     XYZ     |   100 
    c2     |     ABC     |   150
-----------------------------------------------
Table: Employee
----------------------------------------------------------
EmployeeId | EmployeeName  | CompanyId | EmployeeSurveyNo
----------------------------------------------------------
    e1     |     NVERMA     |    c1    |   101 
    e1     |     DAVID      |    c1    |   102
    e2     |     VGUPTA     |    c2    |   151
    e2     |     MAC        |    c2    |   152
----------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

每当员工加入公司时,他都会被要求完成公司特定的调查,并在完成调查后,根据公司表格中的LatestSequenceValue生成" 调查编号 " .

要生成调查,不执行以下步骤:

  1. 从公司表中读取特定于公司的当前序列值(LatestSequenceValue)
  2. 将序列计数增加1
  3. 使用此递增值以" EmployeeSurveyNo " 身份登录员工表
  4. 此外,更新公司表(LatestSequenceValue)中的递增值,以便下一次调查应该得到正确的顺序. …

java oracle sequence

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

如何使用两个jar配置JVM Argument -javaagent

要使用spring AOP,我必须将-javaagent:C:/spring-agent-2.5.6.jar配置为JVM参数.但是有一个已经配置好的 jar,即-javaagent:C:/other.jar

现在我如何使用-javaagent配置两个罐子,以便两个罐子都能正常工作?

在Windows和Linux环境中,可能还有不同的方法可以使用-javaagent配置多个jar.请为两种环境建议解决方案.

java aop javaagents

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

Jersey-Client 1.2 - 泽西客户端性能问题

我使用jersey-client-1.2访问EHCache REST API来放置/获取我自己的自定义对象.

泽西Maven依赖:

<dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

客户代码:

MyObject myObject = new MyObject();
myObject.setName("Narendra");

long start = System.currentTimeMillis();
Client client = Client.create();            
WebResource webResource = client.resource("http://localhost:9080/ehcache-server/rest/mycache/");
System.out.println("Time spend in creating client - " + (System.currentTimeMillis() - start));

start = System.currentTimeMillis();
ClientResponse putResponse = webResource.type("application/x-java-serialized-object").put(ClientResponse.class, SerializationUtils.serialize(myObject));
System.out.println("Time spend in serializing and putting Object into cache - " + (System.currentTimeMillis() - start));

start = System.currentTimeMillis();   
ClientResponse getResponse =  webResource.accept("application/x-java-serialized-object").get(ClientResponse.class);
byte[] bytes = getResponse.getEntity(byte[].class);
System.out.println("Time spend in getting and deseralizing object …
Run Code Online (Sandbox Code Playgroud)

java rest jersey jersey-client

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