我正在研究spring表达式语言,如果你用于配置xml文件,它似乎非常有用.但是,参考文档提供了许多使用以下代码的示例:
ExpressionParser parser = new SpelExpressionParser();
String name = parser.parseExpression
Run Code Online (Sandbox Code Playgroud)
我何时以及为什么要使用它,因为我可以使用常规java来完成所有这些操作.我是否缺少SpelExpressionParser可以使用的一些功能或其他用途?是否还有其他用于spEL的用例我不知道?
是否可以将属性文件转换为枚举.
我有一个有很多设置的propoerty文件.例如
equipment.height
equipment.widht
equipment.depth
and many more like this and not all are as simple as the example
Run Code Online (Sandbox Code Playgroud)
开发人员必须知道密钥才能获得属性的价值.相反,它可以做一些事情,开发人员可以输入MyPropertyEnum.并且键列表将显示在IDE中,就像它显示为Enum一样
MyPropertyEnum.height
Run Code Online (Sandbox Code Playgroud) 我使用aspectj来拦截带注释的方法 @Profile(description="something")
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Profile {
public String description() default "";
}
@Around("com.merc.aop.ctw.aspect.PointcutDefinitions.logAnnotatedMethods(profile)")
public Object profile(ProceedingJoinPoint pjp, Profile profile) throws Throwable {
....
}
@Pointcut("@annotation(com.merc.annotations.Profile)")
protected void logAnnotatedMethods(Profile profile) {
}
Run Code Online (Sandbox Code Playgroud)
但是在使用AJC编译时我得到以下错误消息
formal unbound in pointcut
Run Code Online (Sandbox Code Playgroud) 我有一个简单的测试,我试图更新对象,但合并似乎是执行插入而不是更新.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/app-context.xml","classpath:spring/testdb-context.xml"})
public class UserJPATest {
@Test
public void testUpdate() throws Exception {
System.out.println("update");
User entity = ObjectManager.USER_DAO.findById(3L);
entity.setUsername("harryUpdate");
ObjectManager.USER_DAO.update(entity);
User selEntity = ObjectManager.USER_DAO.findById(3L);
Assert.assertEquals(entity.getUsername(),selEntity.getUsername());
}
Run Code Online (Sandbox Code Playgroud)
}
这是我的更新方法
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public T update(T entity) throws Exception {
try {
T merged = entityManager.merge(entity);
return merged;
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
}
}
Run Code Online (Sandbox Code Playgroud)
更新代码
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public T update(T entity) throws Exception {
try {
T merged = null;
BaseEntity baseEntity = …Run Code Online (Sandbox Code Playgroud) 我有一个多模块maven项目.服务模块依赖于使用依赖标记的域模块.每次构建服务模块时,我都希望它自动构建域模块并从本地存储库中获取最新的域模块.我该怎么做.现在它从本地存储库中选择,但可能不是最新的副本.
我从我的服务模块目录而不是从父目录构建项目.因为我的父模块有很多其他子模块,我对它不感兴趣.
我正在尝试使用线程下载与模式匹配的多个文件.该模式可以匹配1或5或10个差异大小的文件.
为简单起见,我们可以说下载文件的实际代码是downloadFile()方法,而fileNames是与模式匹配的文件名列表.我如何使用线程执行此操作.每个线程只下载一个文件.是否可以在for循环中创建一个新线程.
for (String name : fileNames){
downloadFile(name, toPath);
}
Run Code Online (Sandbox Code Playgroud) 我升级到使用嵌入式maven 3的netbeans 7.我有一个包含许多模块和包含其他模块的模块的项目.我的其他子模块不依赖于内部项目,可以使用相同的配置.在这种情况下,spring-hibernate依赖于作为子模块之一的域而失败.
我的主要项目有这样的东西
<modelVersion>4.0.0</modelVersion>
<artifactId>spring</artifactId>
<packaging>pom</packaging>
<groupId>${masterproject.groupId}</groupId>
<version>${masterproject.version}</version>
Run Code Online (Sandbox Code Playgroud)
我的子模块有以下def
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>spring</artifactId>
<groupId>${masterproject.groupId}</groupId>
<version>${masterproject.version}</version>
</parent>
<artifactId>spring-hibernate</artifactId>
<packaging>pom</packaging>
<dependency>
<groupId>${masterproject.groupId}</groupId>
<artifactId>domain</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我正在使用以下$ {masterproject.groupId},$ {masterproject.version},因为我不想在所有子模块中放置静态值,因为每个子模块都包含父项.不确定这是否是问题的原因.
所有这一切都适用于maven 2.但是使用maven 3我得到以下错误信息
Failed to read artifact descriptor for com.merc:domain:jar:1.0-SNAPSHOT: Failure to find ${masterproject.groupId}:MavenMasterProject:pom:${masterproject.version} in http://repository.springsource.com/maven/bundles/release was cached in the local repository, resolution will not be reattempted until the update interval of com.springsource.repository.bundles.release has elapsed or updates are forced -> [Help 1]
Run Code Online (Sandbox Code Playgroud) 我们有JMeter要求获得95%的生产线.默认情况下,JMeter仅显示90%的行.有没有办法可以使用外部插件或在JMeter本身中使用某些选项来获得95%的值
Muthiah
我在Web应用程序中嵌入了几个项目作为jar.每个项目都有一个log4j.properties文件.在部署Web应用程序时,使用了哪个配置文件以及如何在jar文件中覆盖log4j.xml中的配置.这些罐子不是网络项目.它们更像是服务层代码.在以下方案中加载log4j.properties文件的顺序是什么
Web-project
classes
log4j.properties
ProjectB.jar
com
log4j.properties
ProjectC.jar
com
log4j.properties and so on.
Run Code Online (Sandbox Code Playgroud) 如何在使用Java配置配置Spring时导入属性文件并访问属性.
我想用java做所有事情.有办法吗?
我试过用@ImportResource("classpath:config.properties")但没用.