を働いていない私は私のEJB注釈に問題がありますDAOの使い方は次のとおりです。EJB注釈
public class AddAlertTest extends TestCase {
@EJB
private IOConfigurationDAO ioConfigurationDAO;
public void test() {
ioConfigurationDAO.getManager().getTransaction().begin();
IOConfiguration ioConfig = new IOConfiguration("CH1");
ioConfigurationDAO.getManager().persist(ioConfig);
ioConfigurationDAO.getManager().getTransaction().commit();
int oldSize = ioConfig.getAlerts() == null ? 0 : ioConfig.getAlerts().size();
System.out.println("Created IO configuration with id " + ioConfig.getIoConfigurationId());
ioConfigurationDAO.getManager().getTransaction().begin();
Alert alert = ioConfigurationDAO.addAlert(ioConfig,
Operators[(int) (Math.random() * Operators.length)], new Double(Math.random() * 100));
ioConfigurationDAO.getManager().getTransaction().commit();
int newSize = ioConfig.getAlerts().size();
System.out.println("Created new Alert with id " + alert.getAlertId());
System.out.println("Alert list: " + ioConfig.getAlerts());
System.out.println("Alert is connected to " + alert.getIoConfiguration());
assertEquals(oldSize + 1, newSize);
assertNotNull(ioConfigurationDAO.getManager().find(Alert.class, alert.getAlertId()));
ioConfigurationDAO.getManager().getTransaction().begin();
ioConfigurationDAO.getManager().remove(ioConfig);
ioConfigurationDAO.getManager().getTransaction().commit();
System.out.println("Deleted IO configuration with id " + ioConfig.getIoConfigurationId());
}
しかし、私のIOConfigurationDAOは常にnullなので、私のpersistenceContext注釈は全く機能しません。私のコンソールには何も印刷されていないので、私のpostConstructアノテーションはうまくいきません。私は私の設定で間違っているかわからない
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="JPAService">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.sensorhound.aigateway.domain.Alert</class>
<class>com.sensorhound.aigateway.domain.DataSeriesMeta</class>
<class>com.sensorhound.aigateway.domain.IOConfiguration</class>
<class>com.sensorhound.aigateway.domain.NodeData</class>
<properties>
<property name="hibernate.transaction.jta.platform" value="JBossAS" />
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.0" />
<property name="hibernate.ogm.datastore.provider" value="cassandra_experimental"/>
<property name="hibernate.ogm.datastore.host" value="127.0.0.1:9042"/>
<property name="hibernate.ogm.datastore.database" value="dev"/>
<property name="hibernate.hbm2ddl.auto" value="none"></property>
<property name = "hibernate.show_sql" value = "true" />
<property name = "hibernate.format_sql" value = "true" />
</properties>
</persistence-unit>
</persistence>
:
は、ここに私のpersistence.xmlのです。誰か助けてください。より多くの情報が必要な場合は、私は共有したいと思います。
ありがとうございます!
これを単体テストとして実行しようとしていますか? Arquillianや他のスタンドアロンのEJBコンテナのようなものを使用していない限り、それは決して注入されません。 –
私はあなたに未注入の豆の理由に対する答えを与えました。それがあなたのために有用だったらそれを受け入れてください。 thx –