Announcement Announcement Module
Collapse
No announcement yet.
spring2.5 jetty6.1.14 web container integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring2.5 jetty6.1.14 web container integration

    Hi all,

    hi, anyone know how to get jetty configured with spring? my setup is jetty+derby+spring2.5+hibernate3.3.1+atomikos3.5.2 ; Ive got a web application (war file) which Im deploying in jetty and the war file contains the spring configuration file (applicationContext.xml) ;in my web application im injecting an entitymanagerfactory into one of my classes via @PersistenceUnit but its not getting injected and subsequently I cant open a connection to the database.

    I am just wondering if this is due to a problem in my configuration as Im not loading jetty using spring although I would like to be able to load letty in the usual way and then once spring starts up jetty can then access the beans.

    I am using using a JTA aware datasource in atomikos and hibernate for persistance.

    my config files are :

    relevant part of applicationContext.xml

    <bean id="mydatasource"
    class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init"
    destroy-method="close">
    <property name="uniqueResourceName" value="mydatasource" />
    <property name="xaDataSourceClassName"
    value="org.apache.derby.jdbc.ClientXADataSource" />
    <property name="xaDataSourceProperties"
    value="databaseName=sun-appserv-samples;serverName=localhost;portNumber=1527;user= APP;password=APP" />
    <property name="exclusiveConnectionMode" value="true" />
    <property name="connectionPoolSize" value="20"/>
    <property name="connectionTimeout" value="60"/>
    </bean>


    <!--
    <bean id="mydatasource"
    class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSo urceBean">
    <property name="uniqueResourceName" value="NONXADBMS" />
    <property name="user" value="$APP" />
    <property name="password" value="APP"/>
    <property name="url" value="jdbc:derby://localhost:1527/sun-appserv-samples"/>
    <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
    <property name="poolSize" value="3" />
    <property name="borrowConnectionTimeout" value="120" />
    <property name="testQuery" value="SELECT 1" />
    <property name="reapTimeout" value="0" />
    </bean>
    -->



    <bean id="derbyEntityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="mydatasource" />
    <property name="persistenceUnitName" value="book" />

    <property name="jpaVendorAdapter">
    <bean
    class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="showSql" value="true" />
    <property name="generateDdl" value="false" />
    <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect" />

    </bean>
    </property>

    <property name="jpaPropertyMap">
    <map>
    <entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.Transact ionManagerLookup"/>
    </map>
    </property>
    </bean>

    <bean id="AtomikosTxMgr"
    class="com.atomikos.icatch.jta.UserTransactionMana ger"
    init-method="init" destroy-method="close">
    <property name="forceShutdown" value="true" />
    <property name="startupTransactionService" value="true" />
    <property name="transactionTimeout" value="60" />
    </bean>

    <bean id="AtomikosUsrTx"
    class="com.atomikos.icatch.jta.UserTransactionImp" />

    <bean id="JtaTxManager"
    class="org.springframework.transaction.jta.JtaTran sactionManager">
    <property name="transactionManager" ref="AtomikosTxMgr" />
    <property name="userTransaction" ref="AtomikosUsrTx" />
    <property name="transactionSynchronizationName"
    value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION" />
    </bean>

    relevant part of persistence.xml

    <persistence-unit name="book" transaction-type="JTA"/>

    relevant part of web.xml

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    as you can see I am creating the entitymanagerfactory in spring but its not being injected into an EntityManagerFactory attribute in one of my classes so I have no database access. I tried creating a jndi datasource in jetty and refrencing that in the spring config and also in the persistence.xml file as well, but no luck there either.
    I also tried turning the class which has the EntityManagerFactory attribute into a spring bean; then injecting the class attribute (emf) via spring with the derbyEntityManagerFactory bean in applicationContext.xml above like this:

    class="my.class.BookDAO">
    <property name="emf" ref="derbyEntitymanagerFactory"/>
    </bean>

    but still no luck and the emf property is not visible to spring either.

    The following is the output trace after starting jetty, maybe someone can tell me perhaps what I am doing wrong from this Id appreciate it.

  • #2
    followup to above thread the jetty debug trace ....

    just a followup to the above post, the jetty output trace...the war file im trying to deploy is bookstore2.war

    jp1@vmnode:~/applications/jetty-6.1.14$ java -jar jetty.jar etc/jetty.xml etc/jetty-plus.xml
    Unable to access jarfile jetty.jar
    jp1@vmnode:~/applications/jetty-6.1.14$
    jp1@vmnode:~/applications/jetty-6.1.14$
    jp1@vmnode:~/applications/jetty-6.1.14$ java -jar start.jar etc/jetty.xml etc/jetty-plus.xml
    14-Apr-2009 13:11:29 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
    14-Apr-2009 13:11:31 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: jetty-6.1.14
    14-Apr-2009 13:11:31 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Deploy /home/jp1/applications/jetty-6.1.14/contexts/test-jndi.xml -> org.mortbay.jetty.webapp.WebAppContext@d9660d{/test-jndi,/home/jp1/applications/jetty-6.1.14/contexts/test-jndi.d}
    14-Apr-2009 13:11:31 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Deploy /home/jp1/applications/jetty-6.1.14/contexts/test.xml -> org.mortbay.jetty.webapp.WebAppContext@8c436b{/,/home/jp1/applications/jetty-6.1.14/webapps/test}
    14-Apr-2009 13:11:31 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Deploy /home/jp1/applications/jetty-6.1.14/contexts/javadoc.xml -> org.mortbay.jetty.handler.ContextHandler@633e5e{/javadoc,file:/home/jp1/applications/jetty-6.1.14/javadoc/}
    14-Apr-2009 13:11:36 sun.reflect.NativeMethodAccessorImpl invoke0
    WARNING: Unknown realm: Test JAAS Realm
    14-Apr-2009 13:11:36 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Extract jar:file:/home/jp1/applications/jetty-6.1.14/webapps/cometd.war!/ to /tmp/Jetty_0_0_0_0_8080_cometd.war__cometd__.t2qfkl/webapp
    14-Apr-2009 13:11:40 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Extract jar:file:/home/jp1/applications/jetty-6.1.14/webapps-plus/bookstore2.war!/ to /tmp/Jetty_0_0_0_0_8080_bookstore2.war__bookstore2__tfl psv/webapp
    14-Apr-2009 13:11:41 sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Initializing Spring root WebApplicationContext
    14-Apr-2009 13:11:41 org.springframework.web.context.ContextLoader initWebApplicationContext
    INFO: Root WebApplicationContext: initialization started
    14-Apr-2009 13:11:41 org.springframework.context.support.AbstractApplic ationContext prepareRefresh
    INFO: Refreshing org.springframework.web.context.support.XmlWebAppl icationContext@1a4c5b4: display name [Root WebApplicationContext]; startup date [Tue Apr 14 13:11:41 GMT 2009]; root of context hierarchy
    14-Apr-2009 13:11:42 org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    14-Apr-2009 13:11:42 org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.web.context.support.XmlWebAppl icationContext@1a4c5b4]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@56b93a
    14-Apr-2009 13:11:42 org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@56b93a: defining beans [mydatasource,derbyEntityManagerFactory,AtomikosTxM gr,AtomikosUsrTx,JtaTxManager]; root of factory hierarchy
    14-Apr-2009 13:11:47 org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean createNativeEntityManagerFactory
    INFO: Building JPA container EntityManagerFactory for persistence unit 'book'
    14-Apr-2009 13:11:47 org.hibernate.cfg.annotations.Version <clinit>
    INFO: Hibernate Annotations 3.4.0.GA
    14-Apr-2009 13:11:47 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.3.1.GA
    14-Apr-2009 13:11:47 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    14-Apr-2009 13:11:47 org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : javassist
    14-Apr-2009 13:11:47 org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    14-Apr-2009 13:11:47 org.hibernate.annotations.common.Version <clinit>
    INFO: Hibernate Commons Annotations 3.1.0.GA
    14-Apr-2009 13:11:47 org.hibernate.ejb.Version <clinit>
    INFO: Hibernate EntityManager 3.4.0.GA
    14-Apr-2009 13:11:47 org.hibernate.ejb.Ejb3Configuration configure
    INFO: Processing PersistenceUnitInfo [
    name: book
    ...]
    14-Apr-2009 13:11:48 org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: com.sun.bookstore.database.Book
    14-Apr-2009 13:11:48

    Comment


    • #3
      rest of the jetty output trace from previous post

      org.hibernate.cfg.annotations.EntityBinder bindTable
      INFO: Bind entity com.sun.bookstore.database.Book on table WEB_BOOKSTORE_BOOKS
      14-Apr-2009 13:11:48 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
      INFO: Hibernate Validator not found: ignoring
      14-Apr-2009 13:11:48 org.hibernate.cfg.search.HibernateSearchEventListe nerRegister enableHibernateSearch
      INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListe ner on the classpath. Hibernate Search is not enabled.
      14-Apr-2009 13:11:48 org.hibernate.connection.ConnectionProviderFactory newConnectionProvider
      INFO: Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceCon nectionProvider
      14-Apr-2009 13:11:48 org.hibernate.ejb.connection.InjectedDataSourceCon nectionProvider configure
      INFO: Using provided datasource
      14-Apr-2009 13:11:48 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: RDBMS: Apache Derby, version: 10.1.3.1
      14-Apr-2009 13:11:48 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.1.3.1
      14-Apr-2009 13:11:51 org.hibernate.dialect.Dialect <init>
      INFO: Using dialect: org.hibernate.dialect.DerbyDialect
      14-Apr-2009 13:11:51 org.hibernate.transaction.TransactionFactoryFactor y buildTransactionFactory
      INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransacti onFactory
      14-Apr-2009 13:11:51 org.hibernate.transaction.TransactionManagerLookup Factory getTransactionManagerLookup
      INFO: instantiating TransactionManagerLookup: com.atomikos.icatch.jta.hibernate3.TransactionMana gerLookup
      14-Apr-2009 13:11:51 org.hibernate.transaction.TransactionManagerLookup Factory getTransactionManagerLookup
      INFO: instantiated TransactionManagerLookup
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Automatic flush during beforeCompletion(): disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Automatic session close at end of transaction: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Scrollable result sets: enabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC3 getGeneratedKeys(): disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Connection release mode: auto
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Default batch fetch size: 1
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Generate SQL with comments: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Order SQL updates by primary key: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Order SQL inserts for batching: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
      INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      14-Apr-2009 13:11:51 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
      INFO: Using ASTQueryTranslatorFactory
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Query language substitutions: {}
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JPA-QL strict compliance: enabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Second-level cache: enabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Query cache: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory createRegionFactory
      INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Optimize cache for minimal puts: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Structured second-level cache entries: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Echoing all SQL to stdout
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Statistics: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Deleted entity synthetic identifier rollback: disabled
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Default entity-mode: pojo
      14-Apr-2009 13:11:51 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Named query checking : enabled
      14-Apr-2009 13:11:51 org.hibernate.impl.SessionFactoryImpl <init>
      INFO: building session factory
      14-Apr-2009 13:11:52 org.hibernate.impl.SessionFactoryObjectFactory addInstance
      INFO: Not binding factory to JNDI, no JNDI name configured
      Using init file: /home/jp1/applications/jetty-6.1.14/contexts/test-jndi.d/WEB-INF/classes/jta.properties
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      WARNING: mydatasource: refreshed XAResource
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.console_file_name = tm.out
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.console_file_count = 1
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.automatic_resource_registratio n = true
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.client_demarcation = false
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.threaded_2pc = true
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.serial_jta_transactions = true
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.log_base_dir = /tmp
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.console_log_level = WARN
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.max_actives = 50
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.checkpoint_interval = 500
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.enable_logging = true
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.output_dir = /tmp
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.log_base_name = tmlog
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.console_file_limit = -1
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.max_timeout = 300000
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.tm_unique_name = 127.0.1.1.tm
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING java.naming.factory.initial = com.sun.jndi.rmi.registry.RegistryContextFactory
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING java.naming.provider.url = rmi://localhost:1099
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServ iceFactory
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.force_shutdown_on_vm_exit = false
      14-Apr-2009 13:11:52 com.atomikos.diagnostics.Slf4jConsole println
      INFO: USING com.atomikos.icatch.default_jta_timeout = 10000
      14-Apr-2009 13:11:52 org.springframework.transaction.jta.JtaTransaction Manager checkUserTransactionAndTransactionManager
      INFO: Using JTA UserTransaction: com.atomikos.icatch.jta.UserTransactionImp@ea85b4
      14-Apr-2009 13:11:52 org.springframework.transaction.jta.JtaTransaction Manager checkUserTransactionAndTransactionManager
      INFO: Using JTA TransactionManager: com.atomikos.icatch.jta.UserTransactionManager@efe ff8
      14-Apr-2009 13:11:52 org.springframework.web.context.ContextLoader initWebApplicationContext
      INFO: Root WebApplicationContext: initialization completed in 11132 ms
      Couldn't create bookstore database bean: Couldn't open connection to database: null
      14-Apr-2009 13:11:52 sun.reflect.NativeMethodAccessorImpl invoke0
      INFO: Opened /home/jp1/applications/jetty-6.1.14/logs/2009_04_14.request.log
      14-Apr-2009 13:11:53 sun.reflect.NativeMethodAccessorImpl invoke0
      INFO: Started [email protected]:8080


      as you can see from the following statement above "Couldn't create bookstore database bean: Couldn't open connection to database: null"

      this is line in the jetty trace that inidicates that the @PersistanceUnit annotation injection failed

      Comment

      Working...
      X