2017-11-11 269 views
1

我想升级到我的休眠版本3.2到4.1.0,同时与春季4.3.10集成,我认为我配置好,但当我运行我的应用程序我得到异常。有人可以解决我的问题,我没有得到我在做什么错误。创建与名称控制器bean的错误:通过字段表示的不满意的依赖

栈跟踪

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scmController': Unsatisfied dependency expressed through field 'scm_service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scmServiceImpl': Unsatisfied dependency expressed through field 'scmdao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scmDaoImpl': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'datasource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [DRSCM1] is not bound in this Context. Unable to find [DRSCM1]. 
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [DRSCM1] is not bound in this Context. Unable to find [DRSCM1]. 
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [DRSCM1] is not bound in this Context. Unable to find [DRSCM1]. 
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [DRSCM1] is not bound in this Context. Unable to find [DRSCM1]. 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 

库:

antlr-2.7.7.jar 
aopalliance-1.0.jar 
apache-logging-log4j.jar 
asm-5.1.jar 
axis.jar 
com.springsource.javax.jms-1.1.0.jar 
commons-beanutils-1.7.0.jar 
commons-collections-3.2.1.jar 
commons-digester-1.8.jar 
commons-discovery-0.2.jar 
commons-email-1.0.jar 
commons-fileupload-1.1.1.jar 
commons-io-1.1.jar 
commons-lang-2.5.jar 
commons-logging-1.2-javadoc.jar 
commons-logging-1.2.jar 
dom4j-1.6.1.jar 
dumbster-1.6.jar 
gson-2.2.3.jar 
gwtx-1.5.0.jar 
hibernate-commons-annotations-4.0.1.Final.jar 
hibernate-core-4.1.0.Final.jar 
hibernate-jpa-2.0-api-1.0.1.Final.jar 
hibernate-validator-4.1.0.Final.jar 
icu4j-4.8.1.jar 
itext-2.1.7.jar 
itextpdf-5.4.3.jar 
jackson-annotations-2.8.10.jar 
jackson-core-2.8.10.jar 
jackson-core-asl-1.9.13.jar 
jackson-databind-2.8.10.jar 
jackson-mapper-asl-1.9.13.jar 
jasperreports-3.7.6.jar 
javassist-3.15.0-GA.jar 
javax.servlet-api-3.0.1.jar 
jaxrpc.jar 
jboss-jmx-4.2.2.GA.jar 
jboss-logging-3.1.0.CR2.jar 
jboss-system-4.0.2.jar 
jboss-transaction-api_1.1_spec-1.0.0.Final.jar 
jdom-1.0.jar 
jsp-api-2.2.jar 
jstl-1.2.jar 
jta-1.1.jar 
jxl-2.6.jar 
log4j-1.2.17.jar 
lucene-core-2.3.2.jar 
lucene-highlighter-2.0.0.jar 
mysql-connector-java-5.0.5.jar 
persistence-api-1.0.jar 
poi-3.6.jar 
postgresql-9.3-1104-jdbc4.jar 
quartz-1.5.2.jar 
saaj.jar 
slf4j-api-1.5.6.jar 
slf4j-log4j12-1.5.6.jar 
spring-aop-4.3.10.RELEASE.jar 
spring-beans-4.3.10.RELEASE.jar 
spring-context-4.3.10.RELEASE.jar 
spring-context-support-4.3.10.RELEASE.jar 
spring-core-4.3.10.RELEASE.jar 
spring-expression-4.3.10.RELEASE.jar 
spring-jdbc-4.3.10.RELEASE.jar 
spring-orm-4.3.10.RELEASE.jar 
spring-test-4.3.10.RELEASE.jar 
spring-tx-4.3.10.RELEASE.jar 
spring-web-4.3.10.RELEASE.jar 
spring-webmvc-4.3.10.RELEASE.jar 
stax-api-1.0-2.jar 
validation-api-1.0.0.GA.jar 
wsdl4j.jar 
xom-1.0.jar 

调度员的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:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    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/tx 
http://www.springframework.org/schema/tx/spring-tx.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc.xsd 
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee.xsd"> 


<context:component-scan base-package="com.nic.scm" /> 
    <context:annotation-config /> 
    <mvc:annotation-driven /> 
    <mvc:resources location="/resources/" mapping="/resources/**" /> 

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" /> 

     <!-- <mvc:cache-control max-age="3600" cache-public="true"/> --> 

    <bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="WEB-INF/views/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 


<jee:jndi-lookup id="datasource" jndi-name="java:/DRSCM1" resource-ref="true"/> 


    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="datasource" /> 

     <property name="hibernateProperties"> 
      <props> 
      <prop key="hibernate.default_schema">scm</prop> 
       <prop key="hibernate.dialect"> 
        org.hibernate.dialect.PostgreSQLDialect 
       </prop> 


       <prop key="hibernate.show_sql">true</prop> 
     </props> 
     </property> 
    </bean> 

    <bean id="hibernateTransactionManager" 
     class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
</bean> 


</beans> 

道:

public interface scmDao { 

    List<Users> getUser(String username); 
} 

Implemetation:

@Repository 
public class scmDaoImpl implements scmDao { 

    @Autowired 
    private SessionFactory sessionFactory; 

    public SessionFactory getSessionFactory() { 
     return sessionFactory; 
    } 

    public void setSessionFactory(SessionFactory sessionFactory) { 
     this.sessionFactory = sessionFactory; 
    } 

    @SuppressWarnings({ "unchecked", "deprecation" }) 
    @Transactional 

    public List<Users> getUser(String username){ 

     Session session = sessionFactory.getCurrentSession();  
     List<Users> user_list = new ArrayList<Users>(); 


     String sql= " select uc_user_id,uc_password,uc_user_name,role as role_name,cast(role_id as int) as role_id, " 
       + "u.office_code,off.office_name_en,off.district_code,dc.dist_name_en " 
       + "from users u inner join office_code off on u.office_code=off.office_code " 
       + "inner join user_role ur on u.uc_user_id=ur.user_id inner join roles r on ur.ur_role_id=r.role_id " 
       + "left join district_code dc on dc.dist_code = off.district_code " 
       + "where u.uc_user_name='"+username+"' "; 


     try{ 

      Query qry = session.createSQLQuery(sql);   
      user_list = qry.setResultTransformer(Transformers.aliasToBean(Users.class)).list(); 

     }catch(Exception e){ 
      e.printStackTrace(); 
     } 


     return user_list; 

    } 
} 

服务:

public interface scmService { 

    List<Users> getUser(String username); 

} 

ServiceImple:

@Service 
public class scmServiceImpl implements scmService { 


    @Autowired 
    private scmDao scmdao; 

    public scmDao getScmdao() { 
     return scmdao; 
    } 

    public void setScmdao(scmDao scmdao) { 
     this.scmdao = scmdao; 
    } 

    @Override 
    public List<Users> getUser(String username) { 
     return scmdao.getUser(username); 
    } 
} 

控制器:

@Controller 
@RequestMapping("/") 
public class ScmController { 


    @Autowired 
    private scmService scm_service; 

    public scmService getScm_service() { 
     return scm_service; 
    } 

    public void setScm_service(scmService scm_service) { 
     this.scm_service = scm_service; 
    } 

    HttpSession session; 

    public HttpSession getSession() { 
     return session; 
    } 

    public void setSession(HttpSession session) { 
     this.session = session; 
    } 

    @RequestMapping("login") 
    public String forwardToRegistration(Model model, HttpServletRequest request) { 
     Users user = new Users(); 
     model.addAttribute("loginmodel", user); 
     return "login"; 
    } 
+0

'字符串SQL = ... + “其中u.uc_user_name = ' ”+用户名+“'”; '不要这样做(用户输入查询的字符串连续)。这是SQL注入等待发生:https://stackoverflow.com/questions/1812891/java-escape-string-to-prevent-sql-injection。你也有一个服务层...打开事务,而不是在你的dao层。 – Thierry

回答

相关问题