我试图通过一些在线资料来学习java中的注释.
在下面的代码中,我在这行传递的亲爱的"Hello world"字符串发生了什么:@Test_Target(doTestTarget="Hello World !")?
@Target(ElementType.METHOD)
public @interface Test_Target {
public String doTestTarget();
}
Run Code Online (Sandbox Code Playgroud)
上面是定义的注释,下面是它的用法
public class TestAnnotations {
@Test_Target(doTestTarget="Hello World !")
private String str;
public static void main(String arg[]) {
new TestAnnotations().doTestTarget();
}
public void doTestTarget() {
System.out.printf("Testing Target annotation");
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,它只是打印 Testing Target annotation
请帮帮我,我对注释是全新的.
我需要帮助理解春天的自定义范围我通过参考手册并对它有了一些了解,但是问题就在于我的问题是实际调用我的范围界面实现的get方法时我的理解如果定义了一个带有scope = myscope的bean,那么Spring会在我的作用域实现上调用get方法来检索该对象.但是当我遇到一个例子时,我发现了一些奇怪的东西.
在执行以下语句时不会调用get方法
Object targetBean = getApplicationContext().getBean(task.getBeanName());
Run Code Online (Sandbox Code Playgroud)
但是执行以下声明.
ReflectionUtils.invokeMethod(targetMethod, targetBean, arguments);
Run Code Online (Sandbox Code Playgroud)
任何人都可以通过解释有关自定义范围实现和get方法调用的更多信息来帮助我.
PS:在相关示例中,自定义范围与Threadlocal一起使用..如果任何人可以为我提供一个带有本地线程的海关的工作示例链接,那将是一个很大的帮助
我有以下实体
@Entity
@Table(name = "rule")
public class Rule implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "rule_id")
private Long id;
@ElementCollection(targetClass = Action.class)
@CollectionTable(name = "rule_action", joinColumns = @JoinColumn(name = "rule_id"))
@Enumerated(value = EnumType.STRING)
@Column(name = "action")
private Set<Action> actions;
//After editing as per jbrookover's suggestion adding a new mapping
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "rule_id")
private Set<RuleAction> ruleActions;
}
Run Code Online (Sandbox Code Playgroud)
以下是我的行动
public enum Action {
PHONE, EMAIL, POSTAL,PHONE_OR_EMAIL, SMS;
}
Run Code Online (Sandbox Code Playgroud)
我想获取一个规则列表,其中包含我正在尝试此操作的特定操作集
DetachedCriteria criteria = DetachedCriteria.forClass(Rule.class,"rule");
criteria …Run Code Online (Sandbox Code Playgroud) 我想学习drools和maven任何人都可以帮助我配置drools和maven的链接,并使用它们编写一个基本的hello world示例.
提前致谢
我是Hibernate和Spring的新手,在尝试学习Spring,Hibernate,Maven等时,我只知道如何使用所有这三个来运行一个hello world示例.基于我的基本理解,我被分配了一个执行乐观锁定的任务.据我搜索它,我只能看到我所需要的是在我的映射类中的xml和整数变量版本中添加版本标签并不是很困难.就像这样...
public class MyClass {
...
private int version;
...
}
Run Code Online (Sandbox Code Playgroud)
我的xml应该是这样的
<class name="MyClass">
<id ...>
<version name="version" column="VERSION" access="field">
...
</class>
Run Code Online (Sandbox Code Playgroud)
当第二个用户保存时,hibernate将自动处理版本控制,hibernate发现此用户正在处理陈旧数据并抛出StaleObjectException.
只是想提前确认我的理解.
如果有人可以为我指出一个问候世界的例子,那将会非常有帮助.
我还想提一下,我正在尝试实施"最后提交胜利"的场景
我无法理解load和get之间的区别.当我给session.load时,下面的代码不起作用.它给出了空指针异常.但是当我使用session.get()时,同样有效.
public Employee getEmployee(final String id){
HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException,SQLException {
//return (Employee)session.load(Employee.class, id); doesn't work
return (Employee)session.get(Employee.class, id); //it works
}
};
return (Employee)hibernateTemplate.execute(callback);
}
Run Code Online (Sandbox Code Playgroud)
我还想了解如何将Session对象传递给doInHibernate.
会话何时开始以及何时结束?
堆栈跟踪如下
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:774)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1282)
at $Proxy0.load(Unknown Source)
at hibernate.EmployeeDao$1.doInHibernate(EmployeeDao.java:25)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
at hibernate.EmployeeDao.getEmployee(EmployeeDao.java:29) …Run Code Online (Sandbox Code Playgroud) 因为我试图让我的Spring-Hibernate程序运行三天.由于hibernate2和hibernate3之间的版本差异,我很难找到所涉及的依赖项.最后,我能够使用以下一组依赖项运行程序
现在经过两天的努力,我能够管理上面提到的依赖项,我尝试建立类似的程序,但它抛出以下错误.我尝试在线解决方案,但我找到的解决方案是没有正确版本的spring和hibernate ..任何人都可以告诉我正确的异常原因,还可以正确修改Spring和hibernate的版本
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRecordDAO' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating …Run Code Online (Sandbox Code Playgroud) 我想知道如何在我的代码中进行更改并直接从我的eclipse IDE在服务器上运行它,而不是每次都将我的项目转换为war文件并将其部署在服务器上.
我不希望看到我的更改只反映将其转换为war文件并且每次都在服务器上部署它.我可以在做出一些更改时直接通过我的eclipse IDE直接看到它们.
Plz帮助我,我不知道究竟要在谷歌搜索什么.所以寻求"SO"帮助.
提前致谢.
PS:对不起,我的不好!我应该提供更多信息......我正在开发基于Spring Hibernate的项目......它只有java文件
我正面临着这个奇怪的问题.当我从svn检查项目时,我的整个项目都在目录类型的结构中
即.我的包就像(另一个文件夹中的文件夹)
MainProject
+
+
+++ project_1_name
++++++++ SRC
++++++++++++ COM
++++++++++++++公司名称
++++++ ++++++++++++类名
+
+++ project_2_name ++++++++ SRC
++++++++++++ COM
++++++++++ ++++ companyname
+++++++++++++++++++++++++++
但我希望它像
MainProject
+
project_1_name
+++++ src.com.companyname.className
project_2_name
+++++ src.com.companyname.className
当我在我的工作区中分别从主项目导入一个特定的子项目时,项目就像我看到的那样出现在包装结构中......我第一次使用eclipse.请原谅我这样问一些愚蠢的东西.但请帮帮我
提前致谢
任何人都可以帮助我理解自定义范围.我通过手册和许多在线示例,了解它是如何实现的.但是,我仍然不清楚为什么我们需要一个自定义代理,以及我们为什么会这样做,限制bean的范围.
据我所知,对于单例 - 当我们想要将单个bean赋予所有引用时我们使用单例,并且当我们希望每次引用bean时都给出新引用时我们使用原型.
现在我对自定义范围的理解是
自定义范围 - 我们使用自定义范围作为两者之间的中间点,我们既不想传递单个引用也不是每次都有新引用... 但是它更接近我们所在的单例每次都传递相同的bean,只是从我们的首选位置(例如底层的threadlocal或map).
请帮我把我的概念弄清楚..这里的主要问题是为什么自定义范围?并且当需要它?
java ×8
hibernate ×4
spring ×4
eclipse ×2
scope ×2
annotations ×1
drools ×1
locking ×1
maven ×1
session ×1
svn ×1
thread-local ×1
tomcat ×1
transactions ×1
war ×1