Configuring an HSQLDB in STS - eclipse

I'm trying to put together my first Spring project, and I'm using HSQLDB as my in-memory database for development and testing. My integration test won't run because I can't seem to get the database configured correctly. It's saying there is an issue with my driver class name, but I'm suspecting there's more to it than that. (Side question: is there an easier way to set the database up? How do yo use a database script to do some of the work?) When I run the test, here is the output:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [spring-datasource.xml]: Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:174)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:696)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:671)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:102)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:246)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 25 more
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:173)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:180)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:145)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:167)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:204)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82)
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:206)
... 36 more
Here is my database properties file:
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:mem:wellness
jdbc.username=sa
jdbc.password=
Here is how my database is configured (when I right-click the hsqldb jar file and choose RunAs>Java Application and select the Database Manager). The configuration looks to me to be matching my properties file correctly:
Here is my spring-datasource.xml file. It should be pulling the correct values from the properties file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<context:property-placeholder location="classpath:src/main/resources/database-config-testing.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
</beans>
Here is my application-context.xml file. You can see that I'm importing the datasource xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath*:META-INF/spring*.properties"/>
<context:component-scan base-package="com.kylewalker.wellness"/>
<import resource="spring-datasource.xml"/>
<bean id="employeeDao" class="com.kylewalker.wellness.data.EmployeeDaoJdbcImpl">
<constructor-arg ref="jdbcTemplate"/>
</bean>
<bean id="employeeService" class="com.kylewalker.wellness.services.EmployeeServiceImpl">
<constructor-arg ref="employeeDao"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
</beans>
Here is my integration test:
package com.kylewalker.wellness.integrationtests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.kylewalker.wellness.domain.Employee;
import com.kylewalker.wellness.services.EmployeeService;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("/application-config.xml")
public class FindEmployeeIT {
#Autowired
EmployeeService employeeService;
#Test
public void testAddingEmployees() {
employeeService.addNewEmployee(new Employee("Billy", "Elliot", "bj#home.com"));
employeeService.addNewEmployee(new Employee("Margaret", "Welsh", "mags#amail.com"));
int employeesInDatabase = employeeService.getAllEmployees().size();
assertEquals("There should be two employees in the database.", 2, employeesInDatabase);
}
}

Related

How to solve Java EE EJB Glassfish error javax.naming.NamingException: Invocation exception: Got null ComponentInvocation?

I have a problem with creating a simple databse with EJB. I created a Web Project in Netbeans with Maven. I am using Glassfish 5 however the problem also occurs with glassfish 4.
Here are my classes.
Ui_model.java:
#Named("model")
#Stateless
public class Ui_model implements Serializable{
#Inject
PizzaRepository pizzas;
public Ui_model() {
}
#PostConstruct
public void init(){
Pizza one = new Pizza(1, "Pizza Margaritta", 4.5);
Pizza two = new Pizza(2, "Pizza Napoli", 5);
Pizza three = new Pizza(3, "Pizza Calzone", 6);
pizzas.createDB(one);
pizzas.createDB(two);
pizzas.createDB(three);
}
}
PizzaRepository.java:
#Named
#ApplicationScoped
public class PizzaRepository implements Serializable{
#PersistenceContext(unitName="Unit")
protected EntityManager em;
public void createDB(Pizza pizza){
try{
em.persist(pizza);
}catch(RollbackException e){
System.out.println(e.getMessage());
}
}
}
Pizza.java:
#Entity
public class Pizza implements Serializable{
#Id
int number;
String name;
double price;
public Pizza(int number, String name, double price) {
this.number = number;
this.name = name;
this.price = price;
}
public Pizza(){
}
}
This is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Unit" transaction-type="JTA">
<jta-data-source>java:app/jdbc/testdb</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!-- database connection -->
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
</properties>
</persistence-unit>
</persistence>
This is my glassfish-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="org.apache.derby.jdbc.ClientDataSource"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="derby_net_testdb_usernamePool"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.DataSource"
statement-timeout-in-seconds="-1"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"
wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="testdb"/>
<property name="User" value="username"/>
<property name="Password" value="123456"/>
<property name="URL" value="jdbc:derby://localhost:1527/testdb"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true"
jndi-name="java:app/jdbc/testdb"
object-type="user"
pool-name="java:app/derby_net_testdb_usernamePool"/>
</resources>
My project structure:
When I run this I get the following error:
The strange thing is that this still creates an empty table named Pizza in the testdb but with no entries. So it doesn't mean that the program is not finding the DB itself. I really don't know what to make of that error. The project was much bigger originally but I broke it down to get to the base problem and it doesn't get much easier than this. Still it doesn't work. I would appreciate any advice on how to fix it.
Edit:
asadmin list-jndi-entries prompts:
java:global: com.sun.enterprise.naming.impl.TransientContext
UserTransaction: com.sun.enterprise.transaction.startup.TransactionLifecycleService$2
__internal_java_app_for_app_client__testdb__java:app: com.sun.enterprise.naming.impl.TransientContext
concurrent: com.sun.enterprise.naming.impl.TransientContext
com.sun.enterprise.container.common.spi.util.InjectionManager: com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
jms: com.sun.enterprise.naming.impl.TransientContext
ejb: com.sun.enterprise.naming.impl.TransientContext
jdbc: com.sun.enterprise.naming.impl.TransientContext
Command list-jndi-entries executed successfully.
asadmin list-jndi-entries --context jdbc prompts:
__default: org.glassfish.resourcebase.resources.api.ResourceProxy
__TimerPool: org.glassfish.resourcebase.resources.api.ResourceProxy
sample: org.glassfish.resourcebase.resources.api.ResourceProxy
Command list-jndi-entries executed successfully.
I think the problem is that the jdbc-resource pool-name and the jdbc-connection-pool name do not match. The first has java:app/ prefixed. Try to remove that.
See here for a minimal example: https://github.com/payara/Payara-Examples/blob/master/payara-micro/database-ping/src/main/webapp/WEB-INF/glassfish-resources.xml
I was able to solve the problem by putting the glassfish.xml into an setup file in src. I also got help from a friend who gave me his files.
glassfish.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_testdb_pizzaPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="testdb"/>
<property name="User" value="username"/>
<property name="Password" value="123456"/>
<property name="connectionAttributes" value=";create=true" />
<property name="URL" value="jdbc:derby://localhost:1527/testdb;create=true"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="jdbc/testdb" object-type="user" pool-name="derby_net_testdb_pizzaPool"/>
</resources>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Unit" transaction-type="JTA">
<jta-data-source>jdbc/testdb</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!--<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/ModulDB"/>
<property name="javax.persistence.jdbc.user" value="pizza"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.password" value="123456"/>-->
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
However I then got an error Could not create stateless EJB because of the persist call. That I could resolve by not calling createDB() in the PostConstruct init(). I don't know why but it just didn't work with post construct. Now everything works properly so far. Thank you all very much.

JBPM6 project connect to mysql failed

i installed jbpm6 and mysql,i used PoolingDataSource to start BD,but always unable to find'squenses' tables,i kown it's hibernate'dialect problem,and i want to use persistence.xml to start .
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence
version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="com.test.test" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/jbpm-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<mapping-file>META-INF/Taskorm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>
<!-- manager -->
<class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>
<class>org.jbpm.services.task.impl.model.AttachmentImpl</class>
<class>org.jbpm.services.task.impl.model.ContentImpl</class>
<class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.DelegationImpl</class>
<class>org.jbpm.services.task.impl.model.EscalationImpl</class>
<class>org.jbpm.services.task.impl.model.GroupImpl</class>
<class>org.jbpm.services.task.impl.model.I18NTextImpl</class>
<class>org.jbpm.services.task.impl.model.NotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class>
<class>org.jbpm.services.task.impl.model.PeopleAssignmentsImpl</class>
<class>org.jbpm.services.task.impl.model.ReassignmentImpl</class>
<class>org.jbpm.services.task.impl.model.TaskImpl</class>
<class>org.jbpm.services.task.impl.model.TaskDataImpl</class>
<class>org.jbpm.services.task.impl.model.UserImpl</class>
<!--BAM for task service -->
<class>org.jbpm.services.task.impl.model.BAMTaskSummaryImpl</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
<property name="hibernate.id.new_generator_mappings" value="false" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="jbpm"/>
<property name="hibernate.connection.password" value="jbpm"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm"/>
<property name="hibernate.cglib.use_reflection_optimizer" value="true"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform" />
</properties>
</persistence-unit>
</persistence>
but the error is that:
​Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at test.test.createRuntimeManager(test.java:71)
at test.test.main(test.java:37)
Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [jdbc/jbpm-ds]
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1827)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1785)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
... 6 more
Caused by: javax.naming.NameNotFoundException: unable to find a bound object at name 'jdbc/jbpm-ds'
at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:83)
at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:67)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
... 19 more
i don't kown what i lose

RESTful web-service not found when I deploy app in eclipse

So, I have a Spring Maven web-app with a handful of RESTful web-services. For testing, this project is in Spring (4.1.4.RELEASE). I am using the latest STS (Spring-Eclipse) tool, and I am using Tomcat 8 for the server.
My UserController is designed as follows:
#Controller
#RequestMapping("/users")
public class UserController {
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
#Autowired
private IUserService service;
#RequestMapping(value = "", method = RequestMethod.GET, headers = "Accept=application/json")
public #ResponseBody
ArrayList<UserEntity> getUserList()
{
System.out.println("UserController: getUserList: START");
ArrayList<UserEntity> userEntityList = (ArrayList) service.getAllUsers();
return userEntityList;
}
#RequestMapping(value = "/", method = RequestMethod.GET, headers = "Accept=application/json")
public #ResponseBody
ArrayList<UserEntity> getAllUsers()
{
System.out.println("UserController: getAllUsers: START");
ArrayList<UserEntity> userEntityList = (ArrayList) service.getAllUsers();
return userEntityList;
}
I have a test which runs when I build the app with maven, and this works great:
#RunWith(SpringJUnit4ClassRunner.class)
#WebAppConfiguration
#ContextConfiguration(locations =
{ "classpath:/spring/angular-context.xml", "file:src/main/webapp/WEB-INF/springmvc-servlet.xml" })
#Transactional
public class BaseControllerTests extends TestCase {
#Test
public void testMockGetUserList1() throws Exception
{
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/users/");
this.mockMvc.perform(requestBuilder).andDo(print()).andExpect(status().isOk());
}
#Test
public void testMockGetUserList2() throws Exception
{
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/users");
this.mockMvc.perform(requestBuilder).andDo(print()).andExpect(status().isOk());
}
}
The web-xml file looks like:
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/angular-context.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:/logging/log4j-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Servlets -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/SoccerApp/junithost/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
And the angular-context.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:annotation-config />
<context:component-scan base-package="com.tomholmes.angularjs.phonebook" />
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/phonebook</value>
</property>
<property name="username">
<value>myusername</value>
</property>
<property name="password">
<value>mypassword</value>
</property>
</bean>
<!-- JNDI DataSource for Java EE environments -->
<!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/MyDatabase"/> -->
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="com.tomholmes.angularjs.phonebook.domain" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.tomholmes.net" />
<property name="port" value="587" />
<property name="username" value="myusername" />
<property name="password" value="mypassword" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<!--
<bean id="sendMailService" class="com.tomholmes.angularjs.phonebook.shared.util.SendEmailService">
<property name="mailSender" ref="mailSender" />
</bean>
-->
<bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
So, this project compiles under maven just fine. Under eclipse (STS) with the Tomcat 8 engine, it runs fine, and I can go to my app:
http://localhost:8080/angularjs-phone-book/
and I can see the index.html just fine, so I know the app is out there.
If I go to:
http://localhost:8080/angularjs-phone-book/users
http://localhost:8080/angularjs-phone-book/users/
http://localhost:8080/angularjs-phone-book/rest/users
http://localhost:8080/angularjs-phone-book/rest/users/
Nothing works, and I get a 404 error that this web-service is not found.
But like I said, I know the test works, but I can't see what the exact URL has to be to get there.
I tried deploying the WAR on Tomcat 8 directly, but this web-app won't even start there, supposedly because of logging problems.
If I can provide any more information, please let me know. Any help in finding this would be great. Ultimately I want to have an AngularJS UI on the front-end tied to web-services, and I have to get the web-services working first.
Thanks!
You probably miss the Spring config reference from your web.xml. The unit test runs because you give the reference to the XML directly there, but not in web.xml, so Spring will not scan your controller for annotations.
Use an <init-param> inside <servlet>!
And the correct URL will be the last one, that is, with .../rest/users/, and .../rest/users is also allowed by the help of the browser, I guess.

Tomcat + Eclipse Link + Vaadin, NoClassDefFoundError javax/persistence/Persistence

I'm using Vaadin and Eclipse Link for my web application based on MySQL database.
I have a following class to manage db operations:
public class DatabaseManager {
private static final String PERSISTENCE_UNIT_NAME = "students";
private static EntityManagerFactory factory;
private static EntityManager em;
public DatabaseManager() {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = factory.createEntityManager();
}
public void addEntry(Student student) {
em.getTransaction().begin();
em.persist(student);
em.getTransaction().commit();
}
}
and the following persistence.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="students" transaction-type="RESOURCE_LOCAL">
<class>com.example.simplegradebook.Student</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:C:\\Users\\Ja\\workspace\\SimpleDB;create=true" />
<property name="javax.persistence.jdbc.user" value="test" />
<property name="javax.persistence.jdbc.password" value="test" />
<!-- EclipseLink should create the database schema automatically -->
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
<property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>
I also have a DBTest class in which I test DatabaseManager in console and everything seems to be okay. But when I put for example:
DatabaseManager dbm = new DatabaseManager();
dbm.addEntry(new Student(/*some stuff here*/));
in my VaadinUI class, I get errors like that:
com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: javax/persistence/Persistence
com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1463)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1417)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
java.lang.NoClassDefFoundError: javax/persistence/Persistence
com.example.simplegradebook.DatabaseManager.<init>(DatabaseManager.java:19)
com.example.simplegradebook.SimplegradebookUI.init(SimplegradebookUI.java:44)
com.vaadin.ui.UI.doInit(UI.java:641)
com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1405)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
I have these libraries included in my project:
javax.persistence_2.1.0.v201304241213.jar
javax.persistence.source_2.1.0.v201304241213.jar
Any ideas what may cause the problem?

Spring #Autowired annotation giving null for dozer mapping

Here is my class I am trying to use this annotation and I am getting null for dozerBeanMapper. I also get null for other beans I am trying to use like Jaxb2Mapper, etc
#Service("Transformer")
#Scope("prototype")
public class Transformer {
#Autowired
private Mapper dozerBeanMapper;
public Object testMethod(Object wlpData) throws TransformerException {
MbrReq destObject = null;
destObject = dozerBeanMapper.map(request, MbrReq.class);
return destObject;
}
Here is my configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<sws:annotation-driven />
<context:component-scan base-package="com.xxxxx.xxxx.srvc.membership,com.xxxxx.xxxx.interact.membership.request,com.xxxxx.membership.ws,com.xxxxxx.srvc.membership.generated,com.xxxxx.xxxx.service.transform" />
<!-- WSDL Exposed as memberService -->
<bean id="searchMemDemographics" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<constructor-arg value="/WEB-INF/schema/MemSvc_Binding_HTTP_V0100.wsdl"/>
</bean>
<bean class="org.dozer.spring.DozerBeanMapperFactoryBean">
<property name="mappingFiles">
<list>
<value>classpath:mapping/dozer-global-configuration.xml</value>
<value>classpath:mapping/dozer-bean-mappings.xml</value>
</list>
</property>
</bean>
<oxm:jaxb2-marshaller id="marshaller" contextPath="com.xxxxx.srvc.membership" />
<oxm:jaxb2-marshaller id="reqMarshaller" contextPath="com.xxxxxx.membership.request" />
<oxm:jaxb2-marshaller id="respMarshaller" contextPath="com.xxxxxx.membership.response" />
In web.xml I have this
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/membershipApplicationContext.xml
</param-value>
</context-param>
Anything else I am missing ?
Try adding an id to the bean.
<bean id="dozerBeanMapper" class="org.dozer.spring.DozerBeanMapperFactoryBean">