小编use*_*201的帖子

春天无法注入方面

我正在尝试注入一个方面内的对象.但它总是无效.这个拦截器用于使用aspectj注入域对象,因此除了以下定义之外,不受spring管理

<context:load-time-weaver />
<context:component-scan base-package="framework.interceptor" />

@Aspect
public class LoggingInterceptor {
     @Autowired
     EventLogManager eventLogManager;
 .....
}
Run Code Online (Sandbox Code Playgroud)

我的单元测试是这样的.当调用asa.execute()时,它会被LoggingInterceptor拦截,但LoggingInterceptor.eventLogManager始终为null.但下面的testInjection()工作正常.

 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {     "classpath:applicationContext-dao.xml",
                                    "classpath:applicationContext-service.xml",
                                    "classpath:applicationContext-resources.xml",
                                    "classpath:LoggingTest-context.xml"})
public class LoggingInterceptorTest {

    @Autowired
EventLogManager eventLogManager;

@Test
public void testInjection(){
    Assert.assertNotNull(eventLogManager);
}

@Test
public void testAccountSaveActionAdvice(){
    AccountSaveAction asa = new AccountSaveAction();
    asa.execute();
}
}
Run Code Online (Sandbox Code Playgroud)

我的applicationContext-service.xml具有以下内容

<bean id="eventLogManager"
    class="service.impl.EventLogDBManagerImpl">
    <property name="eventLoggingDao" ref="eventLoggingDao" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我在META-INF中的aop.xml看起来像这样

<aspectj>
<weaver>
    <!-- only weave classes in this package -->
    <include within="action..*" />
</weaver>
<aspects>
    <!-- use only this aspect …
Run Code Online (Sandbox Code Playgroud)

spring

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

Java在构造函数中设置私有字段

常见的设计实践是将实例变量设为私有,并让公共getter和setter访问它们.但很多时候,我在互联网上看到了具有构造函数的代码示例,这些构造函数将值直接分配给私有实例变量,而不是使用构造函数内部的setter.我错过了什么吗?

public class Person{
    private String name;

    public Person(String name){
        //is this right, seems like the whole encapsulation purpose is defeated
        this.name = name;

        //shouldn't this be used
        setName(name);
    }

    public String getName(){
        return this.name;
    }

    public void setName(String name){
        this.name = name;
    }
}
Run Code Online (Sandbox Code Playgroud)

java constructor private-members

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

用于在Ant构建文件及其导入中绘制依赖关系的工具

什么工具可以将Ant构建文件作为输入并显示所有目标依赖项的图形?它也应该考虑进口.

我尝试了vizant,但它不读取导入的文件.

ant diagram visualization build.xml

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

Netbeans maven添加模块

在Netbeans中,如何使用IDE将模块添加到多模块maven项目中.在Eclipse中,我可以右键单击项目>添加>新建>其他> maven模块.netbeans是否具有类似的功能.

netbeans maven

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

hibernate ImprovedNamingStrategy覆盖实体中的表名

我正在使用org.hibernate.cfg.ImprovedNamingStrategy,但对于一个表我已经明确指定了表名

@Table(name="EventLog",schema = "eventlogs")
Run Code Online (Sandbox Code Playgroud)

但是hibernate似乎在寻找event_log.不应该显式命名覆盖ImprovedNamingStrategy提供的命名

hibernate

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

pom内的Maven访问系统属性

在运行maven应用程序时,我传递的是一个系统性的-DconfFolder = c:/ config.在pom中如何访问此值.我希望资源插件将一些文件移动到此confFolder

maven

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

hibernate jpa单元测试autodection不起作用

我在persistence.xml中有以下内容

<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <class>com.merc.model.log.EventLogging</class>
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties>
        <!-- Scan for annotated classes and Hibernate mapping XML files -->
        <property name="hibernate.archive.autodetection" value="class"/>
    </properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

如果我注释掉com.merc.model.log.EventLogging,我会得到Unknown实体异常.

关于为什么自动检测不起作用的任何想法

jpa

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

Java在自定义克隆期间检测循环引用

我正在为每个实体编写自定义克隆方法.对于深层复制,有一种方法可以检测循环引用,或者我必须手动找出它并将克隆限制为单向而不是双向.

例如我们使用hibernate,因此User对象具有对Address和Address的引用,具有对User的引用.试图查看是否可以执行Address和User的深层复制,而不会遇到循环引用问题

java

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

Spring JMS接收主题消息

我正在编写一个简单的教程.我有一个发布者,它发送关于主题的消息和订阅者以接收它.当我启动应用程序时,Spring配置文件加载,然后我收到以下错误

    2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.support.destination.JndiDestinationResolver] - Located object with JNDI name [RateTopic]
2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.support.destination.JndiDestinationResolver] - Located object with JNDI name [RateTopic]
2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.connection.CachingConnectionFactory] - Closing cached Session: ActiveMQSession {id=ID:Reverb0253-PC-62259-1319161839013-0:1:3,started=true}
2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.connection.CachingConnectionFactory] - Closing cached Session: ActiveMQSession {id=ID:Reverb0253-PC-62259-1319161839013-0:1:2,started=true}
2011-10-20 21:50:44,348 WARN [org.springframework.jms.listener.DefaultMessageListenerContainer] - Setup of JMS message listener invoker failed for destination 'RateTopic' - trying to recover. Cause: Destination [RateTopic] is not of expected type [javax.jms.Queue]
org.springframework.jms.support.destination.DestinationResolutionException: Destination [RateTopic] is not of expected type [javax.jms.Queue] …
Run Code Online (Sandbox Code Playgroud)

spring jms

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

Spring批处理FlatFileItemReader读取多个文件

根据spring批处理文档,由于重启问题,他们不建议使用MuliResourceItemReader,并建议在每个文件夹中使用一个文件.

"应该注意的是,与任何ItemReader一样,添加额外的输入(在这种情况下是文件)可能会在重新启动时引起潜在的问题.建议批处理作业使用各自的目录,直到成功完成."

如果我有一个具有以下结构的文件夹dest/< timestamp> /file1.txt,file2.txt

如何配置FlatFileItemReader以读取路径中每个文件夹的模式文件.

spring-batch

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