在weblogic部署期间不会注入依赖关系

时间:2016-09-07 14:01:39

标签: java spring deployment dependency-injection weblogic

我想在weblogic上部署我的项目,但是当我部署战争时,我的spring applicationContext被加载,当它开始保护我的缓存时,它会崩溃,给我一个空指针异常。当我调试时,我看到我在方法中使用的持久性实体类被实例化而没有依赖,这意味着它们没有被注入。

我的实体类标有@Configurable,依赖项的getter和setter方法用@Transient标记。此外,当我运行我的测试时,它确实在实体类中注入了依赖项,当我尝试部署到weblogic时它似乎没有注入。我不知道从哪里开始寻找问题所以我不知道我应该为你提供哪些代码。

关于我应该谷歌或在哪里研究的任何提示将非常感激。此外,如果你想查看一些代码,只需询问,我将添加它。

谢谢,我为缺乏代码而道歉,但我不知道哪个位实际有用,哪些代码无用。

编辑:

添加代码 实体类

@Configurable
@javax.persistence.Entity
@Table(name = "Some_Table")
public class InteractionImpl implements Interaction, Serializable {

    private Long interactionId;
    private Long initiatorEntityNr;
    private Long agentEntityNr;

    transient private BuilderB builderB;
    transient private BuilderA builderA;

    @Id
    @Column(name = "justAnotherID")
    public Long getInteractionId() {
        return interactionId;
    }

    public void setInteractionId(Long interactionId) {
        this.interactionId = interactionId;
    }

    @Column(name = "someCodeB")
    private Long getInitiatorEntityNr() {
        return initiatorEntityNr;
    }

    private void setInitiatorEntityNr(Long initiatorEntityNr) {
        this.initiatorEntityNr = initiatorEntityNr;
    }

    @Column(name = "someCodeA")
    private Long getAgentEntityNr() {
        return agentEntityNr;
    }

    private void setAgentEntityNr(Long agentEntityNr) {

        this.agentEntityNr = agentEntityNr;
    }

    @Transient
    public Agent getAgent() throws CrmEntityCreationException {
        if (getAgentEntityNr() != null)
            return builderA.buildShallowEntity(getAgentEntityNr());
        else
            throw new CrmEntityCreationException("There was no agent entity number so the entity could not be found");
}

    @Transient
    public void setAgent(Agent agentEntity) {
        setAgentEntityNr(agentEntity.getEntityNumber());
    }

    @Transient
    public Customer getInitiator() throws CrmEntityCreationException {
        if (getInitiatorEntityNr() != null) {
            return builderB.buildShallowEntity(getInitiatorEntityNr());
        } else {
            throw new CrmEntityCreationException("The interaction does not contain an initiator entity number");
        }
    }

    @Transient
    public void setInitiator(Customer initiatorEntity) {
        setInitiatorEntityNr(initiatorEntity.getEntityNumber());
    }

    @Transient
    private BuilderB getCustomerBuilder() {
        return builderB;
    }

    @Inject
    @Transient
    public void BuilderB(BuilderB builderB) {
        this.builderB = builderB;
    }

    @Transient
    private BuilderA getBuilderA() {
        return builderA;
    }

    @Inject
    @Transient
    public void setBuilderA(BuilderA builderA) {
        this.builderA = builderA;
    }



}

应用程序上下文

<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:jee="http://www.springframework.org/schema/jee"

       xsi:schemaLocation="
       http://www.springframework.org/schema/jee
       http://www.springframework.org/schema/jee/spring-jee.xsd
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.1.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

    <context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    <tx:annotation-driven transaction-manager="transactionManager" mode="aspectj"/>
    <context:component-scan base-package="crm.persistence"/>
    <context:component-scan base-package="crm.services.impl"/>
    <context:annotation-config/>
    <context:spring-configured/>


    <bean id="hazelcast" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance"/>

    <bean id="httpComponentMessageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender"/>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@someConnection:1521:xe"/>
        <property name="username" value="someUsername"/>
        <property name="password" value="somePassword"/>
    </bean>

    <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="loadTimeWeaver" ref="loadTimeWeaver"></property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="emf"/>
    </bean>

    <bean class="org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect" factory-method="aspectOf">
    </bean>

    <bean id="interactionCache" class="crm.services.impl.Caching.InteractionCacheImpl">
        <property name="ammountOfInteractionToReturn" value="10"/>
    </bean>

    <bean id="interactions" class="crm.persistence.entities.InteractionImpl" scope="prototype"/>

    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="interactionCache"/>
        <property name="targetMethod" value="rehydrateAllCaches"/>
    </bean>

    <bean id="agentCache" class="crm.services.impl.Caching.AgentCacheImpl"/>

    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="agentCache"/>
        <property name="targetMethod" value="rehydrateAll"/>
    </bean>

    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="alertCache"/>
        <property name="targetMethod" value="rehydrateAll"/>
    </bean>
 </beans>

然后是我的spring webservice servlet

    <?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <import resource="classpath:applicationContext.xml"/>

    <!--scans for spring-ws annotation-->
   <sws:annotation-driven/>

</beans>

我的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    </servlet>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

然后是我的weblogic.xml

    <?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">

    <context-root>/CrmService</context-root>
    <container-descriptor>
        <prefer-application-packages>
        <package-name>org.jboss.logging.*</package-name>
        </prefer-application-packages>
    </container-descriptor>
</weblogic-web-app>

从我的应用程序上下文中可以看出,我有两个缓存,我可以补充水分。水合物方法调用DAO以查找相关交互列表(实体类),然后调用getAgent()getInitiator()方法。由于builderAbuilderB未被注入,因此会抛出空指针异常。

只是提醒你它在我的集成测试中注入了这些类,但是当我尝试将它部署到weblogic时却没有。我不使用tomcat

0 个答案:

没有答案