Spring+Hibernate的程序 一直提示上下文加載失敗 求大佬看看問題所在

我在試的一個項目,Spring+Hibernate的程序 一直提示上下文加載失敗 求大佬看看問題所在

錯誤信息

 -250 'javax.annotation.ManagedBean' found and supported for component scanning
七月 08, 2017 12:30:46 上午 org.springframework.web.servlet.FrameworkServlet initServletBean
严重: Context initialization failed
java.lang.IllegalArgumentException

這是配置文件

 <?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" 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.0.xsd   
http://www.springframework.org/schema/tx   
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
http://www.springframework.org/schema/aop   
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
http://www.springframework.org/schema/context    
http://www.springframework.org/schema/context/spring-context-3.1.xsd   
">  

    <!-- JNDI(通过Tomcat)方式配置数据源 -->  
    <!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="${jndiName}"></property> </bean> -->  


       <!-- 引入属性文件 -->  
    <context:property-placeholder location="classpath:config.properties" />  


    <!-- 配置数据源  这里class可以使用不同的驱动-->  
    <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
     <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>  


    <!-- 配置hibernate session工厂 -->  
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <property name="hibernateProperties">  
            <props>  
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>  
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>  
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>  
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>  
                 <prop key="current_session_context_class">thread</prop>    

            </props>  
        </property>  

        <!-- 自动扫描注解方式配置的hibernate类文件 -->  
        <property name="packagesToScan">  
            <list>  
             <!-- 此处与entity实体路径对应 -->  
                <value>pres.uiiooo.model</value>  
            </list>  
        </property>  
    </bean>  



    <!-- 配置事务管理器 -->  
    <bean name="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory"></property>  
    </bean>    


    <!-- 注解方式配置事物 -->  
    <tx:annotation-driven  transaction-manager="transactionManager" />   

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
      http://www.springframework.org/schema/context    
      http://www.springframework.org/schema/context/spring-context-3.1.xsd    
      http://www.springframework.org/schema/mvc    
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">  



    <!-- 支持注解 -->
    <mvc:annotation-driven />

    <!--自动装配DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter -->
    <mvc:default-servlet-handler />


    <!-- 设置自动扫描的路径,用于自动注入bean   这里的路径与自己的项目目录对应--> 
    <!-- 扫描controller路由控制器  -->  
    <context:component-scan base-package="pres.uiiooo.controller" />  
    <context:component-scan base-package="pres.uiiooo.dao,pres.uiiooo.service" />  



    <!-- 视图解析器 -->
        <bean id="viewResolver"  
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="suffix" value=".jsp" />            <!-- 视图文件类型 -->
        <property name="prefix" value="/WEB-INF/views" />  <!-- 视图文件的文件夹路径 -->
    </bean>
    </beans>

這是幾個類

 package pres.uiiooo.controller;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import pres.uiiooo.dao.UserDAO;
import pres.uiiooo.model.User;
import pres.uiiooo.service.UserService;

@Controller
public class Hello {

    @Autowired
    UserService userService;

    @RequestMapping(value = "/Hello")
    public String HelloWorld(Model model) {
        System.out.println("!!!!!!!!!!!");
        User u = new User(1, 2, "fff", "ppp", 1);

        System.out.println(userService.register(u));
        return "HelloWorld";
    }


}

 package pres.uiiooo.dao;



import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import pres.uiiooo.model.User;

@Repository
@Transactional
public class UserDAO {

     @Autowired
     SessionFactory sessionFactory;


    public int register(User u){

         int i = (Integer) sessionFactory.getCurrentSession().save(u);

         System.out.println(i+"!!!");
         if(i!=0)
             return i;
         else 
             return 0;
     }
}

 package pres.uiiooo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pres.uiiooo.dao.UserDAO;
import pres.uiiooo.model.User;

@Service
@Transactional
public class UserService {

    @Autowired
    UserDAO userDAO;

    public int register (User u ){
        return userDAO.register(u);
    }
}

折騰巨久了!! 實在難以入眠!求解決

2个回答

你的spring的bean标签貌似没有class熟悉。id是指这个bean实例化之后的唯一表示。class代表要实例化哪个类。例如这样 id="data source" class="com.x.x.DefaultDataSource" />

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring+Hibernate的程序 一直提示上下文加載失敗 求大佬看看問題所在
# 我在試的一個項目,Spring+Hibernate的程序 一直提示上下文加載失敗 求大佬看看問題所在 錯誤信息 ``` -250 'javax.annotation.ManagedBean' found and supported for component scanning 七月 08, 2017 12:30:46 上午 org.springframework.web.servlet.FrameworkServlet initServletBean 严重: Context initialization failed java.lang.IllegalArgumentException ``` 這是配置文件 ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" 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.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd "> <!-- JNDI(通过Tomcat)方式配置数据源 --> <!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="${jndiName}"></property> </bean> --> <!-- 引入属性文件 --> <context:property-placeholder location="classpath:config.properties" /> <!-- 配置数据源 这里class可以使用不同的驱动--> <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <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> <!-- 配置hibernate session工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="current_session_context_class">thread</prop> </props> </property> <!-- 自动扫描注解方式配置的hibernate类文件 --> <property name="packagesToScan"> <list> <!-- 此处与entity实体路径对应 --> <value>pres.uiiooo.model</value> </list> </property> </bean> <!-- 配置事务管理器 --> <bean name="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 注解方式配置事物 --> <tx:annotation-driven transaction-manager="transactionManager" /> ``` ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 支持注解 --> <mvc:annotation-driven /> <!--自动装配DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter --> <mvc:default-servlet-handler /> <!-- 设置自动扫描的路径,用于自动注入bean 这里的路径与自己的项目目录对应--> <!-- 扫描controller路由控制器 --> <context:component-scan base-package="pres.uiiooo.controller" /> <context:component-scan base-package="pres.uiiooo.dao,pres.uiiooo.service" /> <!-- 视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="suffix" value=".jsp" /> <!-- 视图文件类型 --> <property name="prefix" value="/WEB-INF/views" /> <!-- 视图文件的文件夹路径 --> </bean> </beans> ``` 這是幾個類 ``` package pres.uiiooo.controller; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import pres.uiiooo.dao.UserDAO; import pres.uiiooo.model.User; import pres.uiiooo.service.UserService; @Controller public class Hello { @Autowired UserService userService; @RequestMapping(value = "/Hello") public String HelloWorld(Model model) { System.out.println("!!!!!!!!!!!"); User u = new User(1, 2, "fff", "ppp", 1); System.out.println(userService.register(u)); return "HelloWorld"; } } ``` ``` package pres.uiiooo.dao; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import pres.uiiooo.model.User; @Repository @Transactional public class UserDAO { @Autowired SessionFactory sessionFactory; public int register(User u){ int i = (Integer) sessionFactory.getCurrentSession().save(u); System.out.println(i+"!!!"); if(i!=0) return i; else return 0; } } ``` ``` package pres.uiiooo.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import pres.uiiooo.dao.UserDAO; import pres.uiiooo.model.User; @Service @Transactional public class UserService { @Autowired UserDAO userDAO; public int register (User u ){ return userDAO.register(u); } } ``` 折騰巨久了!! 實在難以入眠!求解決
Spring整合hibernate4时出现no session错误
首先将eclipse抛出的错误贴出来: ``` 严重: Servlet.service() for servlet [springDispatcherServlet] in context with path [/VideoMngSys] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread] with root cause org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:988) at com.vincent.videosys.dao.BaseDao.getSession(BaseDao.java:17) at com.vincent.videosys.dao.UserDao.usernameExist(UserDao.java:29) at com.vincent.videosys.service.UserService.usernameExistService(UserService.java:19) at com.vincent.videosys.controller.home.UserController.usernameExist(UserController.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle (ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod (RequestMappingHandlerAdapter.java:748) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal (RequestMappingHandlerAdapter.java:689) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle (AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931) .... ``` ![项目工程结构如下:](https://img-ask.csdn.net/upload/201601/02/1451707793_69876.png) 下面依次贴出我的相关文件代码: 1.web.xml ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <!-- 加载Spring配置文件,Spring应用上下文,理解层次化的ApplicationContext --> <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> <!-- 可以将POST请求转为PUT请求和DELETE请求 --> <filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- The front controller of this Spring Web application, responsible for handling all application requests --> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </web-app> ``` 2.spring-mvc.xml ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ......> <!-- 向Spring容器注册AutowiredAnnotationBeanPostProcessor、 CommonAnnotationBeanPostProcessor、 PersistenceAnnotationBeanPostProcessor、 RequiredAnnotationBeanPostProcessor,使系统能识别注解 --> <context:annotation-config /> <!-- 使用annotation自动注册bean,并检查@Controller、@Service、@Repository --> <context:component-scan base-package="com.vincent.videosys"></context:component-scan> <!-- 导入资源文件 --> <context:property-placeholder location="classpath:db.properties"/> <!-- 配置C3P0数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${jdbc.user}"></property> <property name="password" value="${jdbc.password}"></property> <property name="driverClass" value="${jdbc.driverClass}"></property> <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property> <property name="initialPoolSize" value="${jdbc.initPoolSize}"></property> <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property> </bean> <!-- 配置SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> <property name="packagesToScan"> <list> <value>com.vincent.videosys.*</value> </list> </property> </bean> <!-- 配置hibernate的事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 定义AutoWired自动注入bean --> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean> <!-- 用注解来实现事务管理 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- 3. 配置事务切入点, 再把事务属性和事务切入点关联起来 --> <aop:config> <aop:pointcut expression="execution(* com.vincent.videosys.service.*.*(..))" id="txPointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/> </aop:config> </beans> ``` 4.hibernate.cfg.xml ``` <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <!-- JDBC connection pool (use the built-in) --> <!-- <property name="connection.pool_size">1</property>--> <!-- 数据库使用的方言 --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Echo all executed SQL to stdout --> <!-- 设置 打印输出 sql 语句 为真 --> <property name="hibernate.show_sql">true</property> <!-- 设置格式为 sql --> <property name="hibernate.format_sql">true</property> <!-- 第一次加载 hibernate 时根据实体类自动建立表结构,以后自动更新表结构 --> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</property> </session-factory> </hibernate-configuration> ``` 5.db.properties jdbc.user=root jdbc.password=root jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbcUrl=jdbc:mysql://localhost:3306/videomngsys jdbc.initPoolSize=5 jdbc.maxPoolSize=10 6. BaseDao.java ``` package com.vincent.videosys.dao; import javax.annotation.Resource; ..... @Repository("baseDao") public class BaseDao{ @Autowired protected SessionFactory sessionFactory; public Session getSession(){ return this.sessionFactory.getCurrentSession(); } } ``` 7.UserDao.java ``` package com.vincent.videosys.dao; import org.hibernate.Query; import org.hibernate.Session; .... @Repository("userDao") public class UserDao extends BaseDao{ protected SessionFactory sessionFactory; /** * 查看该用户名在数据库中是否存在 * 存在返回true * 不存在返回false * 默认返回true * @param username * @return */ public boolean usernameExist(String username){ boolean exist = true; String hqlString = "from user where username = :username"; Session session = super.getSession(); Query query = session.createQuery(hqlString); query.setParameter("username", username); List<User> list = query.list(); if(list.size() > 0) { exist = false; } return exist; } } ``` 8 UserService.java ``` package com.vincent.videosys.service; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; ... @Transactional @Service("userService") public class UserService { @Autowired private UserDao userDao; public boolean usernameExistService(String username){ return userDao.usernameExist(username); } } ``` 9. UserController.java ``` package com.vincent.videosys.controller.home; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; ..... @RequestMapping("/user") @Controller public class UserController { @Autowired private UserService userService; @ResponseBody @RequestMapping(value="/usernameExist",method=RequestMethod.POST) public Map<String, String> usernameExist(@RequestParam("username")String usernameString ){ Map<String, String> resultMap = new HashMap<String, String>(); System.out.println("username: "+usernameString); if(userService.usernameExistService(usernameString)){ resultMap.put("status", "1");//exits } else{ resultMap.put("status", "0");//not exist } return resultMap; } } ``` 每次程序执行到UserController类中的userNameExist方法时,开始调用userService中的方法时,便开始抛出错误.....
junit测试可以加载web.xml中的servlet么?如何加载?
【问题背景】: 1、spring+springMVC+hibernate项目。 2、编写测试用例暂未用到其他测试框架。 3、基于controller写的测试用例。 4、已在base测试类中spring运行器并加载spring配置文件,运行测试用例可获取到对应bean。 ``` @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:aop/applicationContext.xml"}) ``` 【问题】:在用例执行过程中,调用dao的方法中有调用外部配置在web.xml中servlet解析xml,但是此处未能加载到该servlet,导致用例执行失败。报错 ``` 无法加载spring上下文 ``` 已测试将该servlet配置到spring的bean中,但执行依旧不行。 【求助】 请问junit测试过程中是否可以通过加载web.xml来加载启动其中的servlet呢?如果可以怎么配置使用呢?
一个关于SPRING上下文处理顺序的问题
我做了一个登陆页面,然后添加新元素的时候,hibernate的配置文件和实体类都没问题, 在SPRING里加了<value>~~~.hbm.xml</value>后没有问题, 就在把dao配置进去的时候,问题出现了. <bean id=*.dao class=^^^ 然后也不报错,就是不能登录了,说用户名不存在. (开始时可以登录的) 去掉这一句又可以了.. 所以就想问下,这个是什么问题, 然后另外个问题就是,spring里的dao配置和service配置是怎么运作的. 期待大大解答.不甚感激.
Spring集成Hibernate,使用JPA注解方式,新增数据无法提交
<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p>环境:</p> <p style="padding-left: 60px;">spring 3.1</p> <p style="padding-left: 60px;">hibernate 4.2.8 final </p> <p style="padding-left: 60px;">mysql 5.6</p> <p>问题描述:</p> <p style="padding-left: 30px;">调用controller的查询方法,可以正常返回数据</p> <p style="padding-left: 30px;">调用controller的创建方法,即:新增数据,控制台打印出了读取和修改序号表的sql,但是没有打印插入数据的sql,数据库表中也没有新增数据。</p> <p style="padding-left: 30px;">怀疑是spring控制的事务没有提交,但是排查了两三天,从网上找了各种方法,都没有解决问题。</p> <p style="padding-left: 30px;">请各位大侠拉小弟一把,实在是找不到事务为什么没有提交。</p> <p> </p> <p style="padding-left: 30px;">web.xml</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt; &lt;!-- 欢迎界面 --&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;!-- spring框架 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- 上下文配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/applicationContext.xml, /WEB-INF/config/**/*.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- spring mvc --&gt; &lt;servlet&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;!-- 拦截所有url --&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;!-- 回话有效期30分钟 --&gt; &lt;session-config&gt; &lt;session-timeout&gt;30&lt;/session-timeout&gt; &lt;/session-config&gt; &lt;!-- log4j日志 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- log4j日志配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/properties/log4j.properties&lt;/param-value&gt; &lt;/context-param&gt; &lt;/web-app&gt;</pre> <p> applicationContext.xml</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- 注解配置 --&gt; &lt;context:annotation-config /&gt; &lt;!--允许使用注解方式配置事务 --&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.lxl" /&gt; &lt;!-- 对标注@PersistenceContext的类经行增强,引入代理后的EntityManager实例 --&gt; &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt; &lt;!-- 对标注@Repository的类经行增强,将EntityManager异常转换为SpringDAO体系的异常 --&gt; &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt; &lt;!-- 属性文件 --&gt; &lt;context:property-placeholder location="/WEB-INF/properties/**/*.properties" /&gt; &lt;!-- 数据源 --&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.username}" /&gt; &lt;property name="password" value="${jdbc.password}" /&gt; &lt;/bean&gt; &lt;!-- JPA 实体管理工厂 --&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="persistenceUnitName" value="ServicePlatform" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="true" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- JPA 事务管理 --&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;/beans&gt;</pre> <p> dispatcher-servlet.xml</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- 默认的注解映射的支持 --&gt; &lt;mvc:annotation-driven /&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.lxl" /&gt; &lt;!-- 配置一下对json数据的转换 &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;&lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; --&gt; &lt;!-- 视图解析器 --&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/view" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;/bean&gt; &lt;!-- 对静态资源文件的访问 方案一 (二选一) --&gt; &lt;mvc:default-servlet-handler /&gt; &lt;!-- 对静态资源文件的访问 方案二 (二选一) &lt;mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/&gt; &lt;mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/&gt; &lt;mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/&gt; --&gt; &lt;/beans&gt;</pre> <p> </p> <p> </p> <p style="padding-left: 30px;">persistence.xml</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;persistence-unit name="ServicePlatform" transaction-type="RESOURCE_LOCAL"&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">实体bean</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.entity; import java.io.Serializable; import java.sql.Timestamp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "bd_id") public class Identity implements Serializable { private static final long serialVersionUID = -8763611811485844772L; @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; @Column(length = 100) private String code; private Long value; @Column(length = 10) private String prefix; @Column(length = 10) private String suffix; @Column(length = 255) private String description; private Integer length; @Column(length = 30) private String creator; @Column(name = "create_date") private Timestamp createDate; @Column(length = 30) private String modifier; @Column(name = "modify_Date") private Timestamp modifyDate; private Boolean dr; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public Long getValue() { return value; } public void setValue(Long value) { this.value = value; } public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } public String getSuffix() { return suffix; } public void setSuffix(String suffix) { this.suffix = suffix; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Integer getLength() { return length; } public void setLength(Integer length) { this.length = length; } public String getCreator() { return creator; } public void setCreator(String creator) { this.creator = creator; } public Timestamp getCreateDate() { return createDate; } public void setCreateDate(Timestamp createDate) { this.createDate = createDate; } public String getModifier() { return modifier; } public void setModifier(String modifier) { this.modifier = modifier; } public Timestamp getModifyDate() { return modifyDate; } public void setModifyDate(Timestamp modifyDate) { this.modifyDate = modifyDate; } public Boolean getDr() { return dr; } public void setDr(Boolean dr) { this.dr = dr; } @Override public String toString() { return "Identity [id=" + id + ", code=" + code + ", value=" + value + ", prefix=" + prefix + ", suffix=" + suffix + ", description=" + description + ", length=" + length + ", creator=" + creator + ", createDate=" + createDate + ", modifier=" + modifier + ", modifyDate=" + modifyDate + ", dr=" + dr + "]"; } } </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">IdentityDaoImpl.java</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.dao; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.lxl.bsp.api.exception.ServicePlatformException; import com.lxl.bsp.identity.entity.Identity; @Repository public class IdentityDaoImpl implements IIdentityDao { @PersistenceContext private EntityManager em; @Transactional(propagation = Propagation.REQUIRED) public Identity create(Identity data) { em.persist(data); return data; } @Override public Identity retriver(String id) throws ServicePlatformException { Long pk = Long.valueOf(id); return em.find(Identity.class, pk); } @Override public Identity update(Identity data) throws ServicePlatformException { em.persist(data); return data; } @Override public void delete(String id) throws ServicePlatformException { em.remove(retriver(id)); } } </pre> <p> IdentityController.java</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.controller; import java.sql.Timestamp; import java.util.Calendar; import javax.annotation.Resource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.lxl.bsp.api.exception.ServicePlatformException; import com.lxl.bsp.identity.dao.IIdentityDao; import com.lxl.bsp.identity.entity.Identity; @Controller @RequestMapping("identity") public class IdentityController { private static Log log = LogFactory.getLog(IdentityController.class); @Resource private IIdentityDao dao; @RequestMapping("retriver") @ResponseBody public Identity retriver(@RequestParam String id) throws ServicePlatformException { return dao.retriver(id); } @RequestMapping("create") @ResponseBody public Identity create() throws ServicePlatformException { int i = 1; Identity data = new Identity(); data.setCode("code" + i); Calendar c = Calendar.getInstance(); data.setCreateDate(new Timestamp(c.getTime().getTime())); data.setCreator("creator" + i); data.setDescription("description" + i); data.setDr(false); // data.setId("id" + Integer.toString(i)); data.setLength(30); data.setModifier("modifier" + i); data.setModifyDate(new Timestamp(c.getTime().getTime())); data.setPrefix("prefix"); data.setSuffix("suffix"); data.setValue(0L); Identity returnData = dao.create(data); log.debug(returnData); return returnData; } @RequestMapping("update") @ResponseBody public Identity update() throws ServicePlatformException { int i = 1; Identity data = new Identity(); data.setCode("1"); Calendar c = Calendar.getInstance(); data.setCreateDate(new Timestamp(c.getTime().getTime())); data.setCreator("creator" + i); data.setDescription("description" + i); data.setDr(false); // data.setId("id" + Integer.toString(i)); data.setLength(30); data.setModifier("modifier" + i); data.setModifyDate(new Timestamp(c.getTime().getTime())); data.setPrefix("prefix"); data.setSuffix("suffix"); data.setValue(0L); Identity returnData = dao.update(data); log.debug(returnData); return returnData; } @RequestMapping("delete") public void delete(@RequestParam String id) throws ServicePlatformException { dao.delete(id); } } </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">数据表结构DDL</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="sql">-- ---------------------------- -- Table structure for bd_id -- ---------------------------- DROP TABLE IF EXISTS `bd_id`; CREATE TABLE `bd_id` ( `id` bigint(30) NOT NULL, `code` varchar(100) DEFAULT NULL, `create_date` datetime DEFAULT NULL, `creator` varchar(30) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, `dr` tinyint(1) DEFAULT NULL, `length` int(11) DEFAULT NULL, `modifier` varchar(30) DEFAULT NULL, `modify_Date` datetime DEFAULT NULL, `prefix` varchar(10) DEFAULT NULL, `suffix` varchar(10) DEFAULT NULL, `value` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre> <p> </p> <p> </p> <p style="padding-left: 30px;">附件中是项目压缩包,只要电脑上安装了数据库,解压即可运行,数据库名称是osd</p> <p> </p> </div>
在HttpsessionListener中操作数据库,getBean获取不了怎么办?在线等
在使用SpringMVC+hibernate框架时,想要在session到期后,可以更新数据库中用户在线状态。 于是我自定义一个类 SessionListener implements HttpSessionListener,并实现了方法sessionDestroyed,代码如下: 其中:HttpsessionListener的实现类也放在了Dao的包里面 ``` @Override public void sessionDestroyed(HttpSessionEvent se) { // TODO Auto-generated method stub HttpSession session = se.getSession(); LoginUserSessionVO user = (LoginUserSessionVO)session.getAttribute("User"); Integer userTID = user.getUserTID(); Timestamp logoutTime = new Timestamp(System.currentTimeMillis()); //获取Java bean UserInfoTableDao userInfoDao = (UserInfoTableDao)this.getObjectFromApplication(session.getServletContext(), "UserInfoTableDaoImpl"); //注销当前用户 userInfoDao.setLogoutInfoByUserTID(0, logoutTime, userTID); System.out.println("用户已超时退出"); } /** * 通过WebApplicationContextUtils 得到Spring容器的实例。根据bean的名称返回bean的实例。 * @param servletContext :ServletContext上下文。 * @param beanName :要取得的Spring容器中Bean的名称。 * @return 返回Bean的实例。 */ private Object getObjectFromApplication(ServletContext servletContext,String beanName) { ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); return applicationContext.getBean(beanName); } ``` 然后运行时报错: ``` 严重: Session event listener threw exception org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'UserInfoTableDaoImpl' is defined ``` 不知道是什么原因?网上找了很久都没找到,是bean没有get到还是bean的名字不对?应该get哪个啊?求大神解救,在线等!
springboot 配置多库之后,mybatis在控制台不打印sql语句了
springboot项目 单库下,mybatis只需要添加如下配置,就可以打印sql语句 ```xml <!-- 打印查询语句 --> <setting name="logImpl" value="STDOUT_LOGGING" /> ``` 但是多库环境下,mybatis不论怎么设置,都无法打印sql语句..... ---- ---- 项目中的相关配置: mybatis配置: ```xml <!-- 设置运行参数 --> <settings> <!-- 全局映射器启用缓存 --> <setting name="cacheEnabled" value="true" /> <!-- 查询时,关闭关联对象及时加载以提高性能 --> <setting name="lazyLoadingEnabled" value="false" /> <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指定),不会加载关联表的所有字段,以提高性能 --> <setting name="aggressiveLazyLoading" value="false" /> <!-- 对于位置的SQL查询,允许返回不同的结果集以达到通用的效果 --> <setting name="multipleResultSetsEnabled" value="true" /> <!-- 允许使用列标签代替列明 --> <setting name="useColumnLabel" value="true" /> <!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值), 数据表的pk生成策略将被覆盖 --> <setting name="useGeneratedKeys" value="true" /> <!-- 给予被嵌套的resultMap以字段-属性的映射支持 --> <setting name="autoMappingBehavior" value="PARTIAL" /> <!-- 对于批量更新操作缓存SQL以提高性能 --> <setting name="defaultExecutorType" value="REUSE" /> <!-- 数据库超过25000秒仍未响应则超时 --> <!--<setting name="defaultStatementTimeout" value="25000" />--> <!-- 打印查询语句 --> <setting name="logImpl" value="STDOUT_LOGGING" /> <!-- 开启驼峰--> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> ``` logback配置: ```xml <?xml version="1.0" encoding="UTF-8"?> <configuration scan="true"> <!-- 属性1:每个logger都关联到logger上下文,默认上下文名称为“default”。 但可以使用设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改,可以通过%contextName来打印日志上下文名称。 --> <contextName>logback</contextName> <!--属性2:定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> <!-- <springProfile name="dev"> <property name="LOG_PATH" value="D://care-management-statisticserver-logs"/> </springProfile> <springProfile name="test"> <property name="LOG_PATH" value="/data/tomcat_jar/taixin_care/care-management-statisticserver/logs"/> </springProfile> <springProfile name="prod"> <property name="LOG_PATH" value="/data1/logs/care-management-statisticserver"/> </springProfile> --> <property name="LOG_PATH" value="${LOG_FILE}"/> <!--appender用来格式化日志输出节点,有俩个属性name和class,class用来指定哪种输出策略,常用就是控制台输出策略和文件输出策略。--> <!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>info</level> </filter> <encoder> <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n</pattern> </encoder> </appender> <!--<include resource="org/springframework/boot/logging/logback/base.xml"/>--> <!-- 说明: 1、日志级别及文件 日志记录采用分级记录,级别与日志文件名相对应,不同级别的日志信息记录到不同的日志文件中 例如:error级别记录到log_error_xxx.log或log_error.log(该文件为当前记录的日志文件),而log_error_xxx.log为归档日志, 日志文件按日期记录,同一天内,若日志文件大小等于或大于2M,则按0、1、2...顺序分别命名 例如log-level-2013-12-21.0.log 其它级别的日志也是如此。 2、文件路径 若开发、测试用,在Eclipse中运行项目,则到Eclipse的安装路径查找logs文件夹,以相对路径../logs。 若部署到Tomcat下,则在Tomcat下的logs文件中 3、Appender FILEERROR对应error级别,文件名以log-error-xxx.log形式命名 FILEWARN对应warn级别,文件名以log-warn-xxx.log形式命名 FILEINFO对应info级别,文件名以log-info-xxx.log形式命名 FILEDEBUG对应debug级别,文件名以log-debug-xxx.log形式命名 CONSOLE将日志信息输出到控制上,为方便开发测试使用 --> <!-- 日志记录器,日期滚动记录 --> <appender name="FILEERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在记录的日志文件的路径及文件名 --> <file>${LOG_PATH}/error_statisticserver.log</file> <!-- 日志记录器的滚动策略,按日期,按大小记录 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 归档的日志文件的路径,例如今天是2013-12-21日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。 而2013-12-21的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${LOG_PATH}/error-statisticserver-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!-- 表示只保留最近30天的日志,以防止日志填满整个磁盘空间。--> <maxHistory>30</maxHistory> <!--用来指定日志文件的上限大小,例如设置为1GB的话,那么到了这个值,就会删除旧的日志。--> <totalSizeCap>1GB</totalSizeCap> <!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始, 命名日志文件,例如log-error-2013-12-21.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>100MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!-- 追加方式记录日志 --> <append>true</append> <!-- 日志文件的格式 --> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n</pattern> <charset>utf-8</charset> </encoder> <!-- 此日志文件只记录error级别的 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- 日志记录器,日期滚动记录 --> <appender name="FILEINFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在记录的日志文件的路径及文件名 --> <file>${LOG_PATH}/info_statisticserver.log</file> <!-- 日志记录器的滚动策略,按日期,按大小记录 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 归档的日志文件的路径,例如今天是2013-12-21日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。 而2013-12-21的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${LOG_PATH}/info-statisticserver-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!-- 表示只保留最近30天的日志,以防止日志填满整个磁盘空间。--> <maxHistory>30</maxHistory> <!--用来指定日志文件的上限大小,例如设置为1GB的话,那么到了这个值,就会删除旧的日志。--> <totalSizeCap>1GB</totalSizeCap> <!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始,命名日志文件,例如log-error-2013-12-21.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>100MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!-- 追加方式记录日志 --> <append>true</append> <!-- 日志文件的格式 --> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n</pattern> <charset>utf-8</charset> </encoder> <!-- 此日志文件只记录info级别的 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- <logger>用来设置某一个包或者具体的某一个类的日志打印级别、以及指定<appender>。<logger>仅有一个name属性,一个可选的level和一个可选的addtivity属性。 --> <logger name="org.springframework" level="INFO"/> <logger name="org.apache" level="ERROR"/> <logger name="org.hibernate.validator" level="ERROR"/> <!--<logger name="org.thymeleaf" level="ERROR"/>--> <logger name="org.springframework.context.annotation" level="ERROR"/> <!-- springProfile多环境日志输出,据不同环境(prod:生产环境,test:测试环境,dev:开发环境)来定义不同的日志输出--> <springProfile name="dev" /> <root level="INFO"> <appender-ref ref="FILEERROR"/> <appender-ref ref="FILEINFO"/> <appender-ref ref="STDOUT"/> </root> <!-- 可以启动服务的时候指定 profile (如不指定使用默认),如指定prod 的方式为: java -jar xxx.jar –spring.profiles.active=prod--> </configuration> ``` application.properties部分配置: ```properties #配置文件 logging.level.tk.mybatis=TRACE spring.freemarker.cache=false spring.freemarker.request-context-attribute=request mybatis.type-aliases-package=com.mtpf.domain mybatis.mapper-locations=classpath:mapper/*.xml mapper.mappers=com.mtpf.util.MyMapper mapper.not-empty=false mapper.identity=MYSQL pagehelper.helperDialect=mysql #true 是超出最大页码返回数据 false超出最大页码不返回数据 pagehelper.reasonable=${PAGEHELPER_REASONABLE} pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql ```
关于springMVC注解注入失败的问题
注解都写了,没发现哪有遗漏,个人认为是环境配置的问题,求解答 dao ``` package dao; import java.util.List; import org.springframework.orm.hibernate4.support.HibernateDaoSupport; import org.springframework.stereotype.Repository; import entity.Food; @Repository public class FoodDao extends HibernateDaoSupport{ ``` service ``` package Logic; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import dao.FoodDao; import entity.Food; @Service public class FoodLogic { ``` controller ``` import entity.Food; @Controller @RequestMapping("") public class AddFoodController extends AbstractController{ @RequestMapping("/list") public ModelAndView getList(HttpServletRequest request, HttpServletResponse response) { List<Food> foodlist = this.foodLogic.selectAllFood(); response.setCharacterEncoding("UTF-8"); try { PrintWriter write = response.getWriter(); write.write(getJson(foodlist)); write.flush(); write.close(); } catch (IOException e) { e.printStackTrace(); } return this.listView(); } @ResponseBody public String getJson(List list) { JSONObject jsonDate = new JSONObject(); jsonDate.put("list", list); return jsonDate.toString(); } } package Controller.foodController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.servlet.ModelAndView; import Logic.FoodLogic; public class AbstractController { @Autowired public FoodLogic foodLogic; public ModelAndView listView() { return new ModelAndView("food/list"); } public ModelAndView editView() { return new ModelAndView("food/edit"); } public ModelAndView viewView() { return new ModelAndView("food/view"); } } ``` xml ``` <?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:mvc="http://www.springframework.org/schema/mvc" 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-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- 加载Spring的全局配置文件 --> <!-- scan the package and the sub package --> <context:component-scan base-package="Controller"/> <!-- don't handle the static resource --> <mvc:default-servlet-handler /> <!-- if you use annotation you must configure following setting --> <mvc:annotation-driven /> <!-- configure the InternalResourceViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver"> <!-- 前缀 --> <property name="prefix" value="/htm/" /> <!-- 后缀 --> <property name="suffix" value=".html" /> </bean> ``` web.xml ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>OrderMealManager</display-name> <!-- <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> --> <!-- 监听spring上下文容器 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!--configure the setting of springmvcDispatcherServlet and configure the mapping--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <!-- <load-on-startup>1</load-on-startup> --> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ``` 错误信息 ``` 八月 08, 2017 12:59:18 下午 org.springframework.context.support.AbstractApplicationContext refresh 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFoodController': Unsatisfied dependency expressed through field 'foodLogic': No qualifying bean of type [Logic.FoodLogic] found for dependency [Logic.FoodLogic]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [Logic.FoodLogic] found for dependency [Logic.FoodLogic]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 八月 08, 2017 12:59:18 下午 org.springframework.web.servlet.FrameworkServlet initServletBean 严重: Context initialization failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFoodController': Unsatisfied dependency expressed through field 'foodLogic': No qualifying bean of type [Logic.FoodLogic] found for dependency [Logic.FoodLogic]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [Logic.FoodLogic] found for dependency [Logic.FoodLogic]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} ```
跨数据库单元测试如何做
使用spring+hibernate+jta,涉及到两个数据库,配置了两个数据源,如何用spring-mock做单元测试? [b]问题补充:[/b] 其实我想用mock在真实的跨库操作中做测试,比如dao涉及到两个数据库的事务,这种dao用spring-mock怎么测? [b]问题补充:[/b] 我在配置文件中配置了JTA的userTransaction,而UserTransaction需要web容器,从而导致JNDI找不到上下文;在spring注入abstractTransactionalDataSourceSpringContextTests的datasource时,只会注入一个。这种情况怎么用spring-mock测试。我知道一种替代方法是全部手动,不使用spring注入。如果用注入,该怎么做,能不能用mock模拟JNDI,然后使用配置文件来测试。
贴一层tomcat启动代码,前辈们看一看项目是哪出了问题 启动特慢,
``` D:\apache-tomcat-8.0.30\bin\catalina.bat run [2019-05-13 10:07:54,976] Artifact vlis1:war exploded: Waiting for server connection to start artifact deployment... Using CATALINA_BASE: "C:\Users\Administrator\.IntelliJIdea2018.3\system\tomcat\Unnamed_vlis" Using CATALINA_HOME: "D:\apache-tomcat-8.0.30" Using CATALINA_TMPDIR: "D:\apache-tomcat-8.0.30\temp" Using JRE_HOME: "D:\feiq\Recv Files\jdk1.8.0_101" Using CLASSPATH: "D:\apache-tomcat-8.0.30\bin\bootstrap.jar;D:\apache-tomcat-8.0.30\bin\tomcat-juli.jar" Connected to the target VM, address: '127.0.0.1:14110', transport: 'socket' 2019-05-13 22:08:24 JRebel: Starting logging to file: C:\Users\Administrator\.jrebel\jrebel.log 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: ############################################################# 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: JRebel Agent 2019.1.1 (201904120806) 2019-05-13 22:08:24 JRebel: (c) Copyright 2007-2019 Rogue Wave Software, Inc. 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: Over the last 1 days JRebel prevented 2019-05-13 22:08:24 JRebel: at least 0 redeploys/restarts saving you about 0 hours. 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: License acquired from License Server: http://139.199.89.239:1008 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: Licensed to Administrator. 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: You are using an offline license. 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: 2019-05-13 22:08:24 JRebel: ############################################################# 2019-05-13 22:08:24 JRebel: 13-May-2019 22:08:31.677 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.30 13-May-2019 22:08:31.681 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 1 2015 22:30:46 UTC 13-May-2019 22:08:31.681 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.30.0 13-May-2019 22:08:31.681 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 7 13-May-2019 22:08:31.682 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.1 13-May-2019 22:08:31.683 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 13-May-2019 22:08:31.683 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: D:\feiq\Recv Files\jdk1.8.0_101\jre 13-May-2019 22:08:31.684 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_101-b13 13-May-2019 22:08:31.684 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 13-May-2019 22:08:31.684 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Administrator\.IntelliJIdea2018.3\system\tomcat\Unnamed_vlis 13-May-2019 22:08:31.687 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: D:\apache-tomcat-8.0.30 13-May-2019 22:08:31.688 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Drebel.base=C:\Users\Administrator\.jrebel 13-May-2019 22:08:31.698 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Drebel.env.ide.plugin.version=2019.1.1 13-May-2019 22:08:31.699 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Drebel.env.ide.version=2018.3 13-May-2019 22:08:31.699 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Drebel.env.ide.product=IU 13-May-2019 22:08:31.699 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Drebel.env.ide=intellij 13-May-2019 22:08:31.700 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Drebel.notification.url=http://localhost:17434 13-May-2019 22:08:31.700 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentpath:C:\Users\Administrator\.IntelliJIdea2018.3\config\plugins\jr-ide-idea\lib\jrebel6\lib\jrebel64.dll 13-May-2019 22:08:31.700 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:14110,suspend=y,server=n 13-May-2019 22:08:31.701 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -javaagent:C:\Users\Administrator\.IntelliJIdea2018.3\system\captureAgent\debugger-agent.jar 13-May-2019 22:08:31.701 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote= 13-May-2019 22:08:31.701 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099 13-May-2019 22:08:31.702 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false 13-May-2019 22:08:31.702 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false 13-May-2019 22:08:31.703 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1 13-May-2019 22:08:31.703 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Administrator\.IntelliJIdea2018.3\system\tomcat\Unnamed_vlis\conf\logging.properties 13-May-2019 22:08:31.703 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 13-May-2019 22:08:31.704 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-8.0.30\endorsed 13-May-2019 22:08:31.704 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Administrator\.IntelliJIdea2018.3\system\tomcat\Unnamed_vlis 13-May-2019 22:08:31.704 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:\apache-tomcat-8.0.30 13-May-2019 22:08:31.704 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:\apache-tomcat-8.0.30\temp 13-May-2019 22:08:31.705 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.1.33 using APR version 1.5.1. 13-May-2019 22:08:31.705 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 13-May-2019 22:08:33.367 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.1m 19 Mar 2015) 13-May-2019 22:08:34.504 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8989"] 13-May-2019 22:08:34.556 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"] 13-May-2019 22:08:34.565 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 5481 ms 13-May-2019 22:08:34.793 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 13-May-2019 22:08:34.794 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.30 13-May-2019 22:08:35.173 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8989"] 13-May-2019 22:08:35.231 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"] 13-May-2019 22:08:35.338 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 771 ms Connected to server [2019-05-13 10:08:35,773] Artifact vlis1:war exploded: Artifact is being deployed, please wait... 13-May-2019 22:08:45.204 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\apache-tomcat-8.0.30\webapps\manager 13-May-2019 22:08:46.818 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 13-May-2019 22:08:48.182 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\apache-tomcat-8.0.30\webapps\manager has finished in 2,977 ms 13-May-2019 22:09:30.026 INFO [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 2019-05-13 22:09:35 JRebel: Monitoring Spring bean definitions in 'F:\vlis1\target\vlis-1.0-SNAPSHOT\WEB-INF\classes\applicationContext-resources.xml'. 2019-05-13 22:09:36 JRebel: Monitoring Spring bean definitions in 'F:\vlis1\target\vlis-1.0-SNAPSHOT\WEB-INF\classes\applicationContext-dao.xml'. 2019-05-13 22:09:38 JRebel: Monitoring Spring bean definitions in 'F:\vlis1\target\vlis-1.0-SNAPSHOT\WEB-INF\classes\applicationContext-service.xml'. 2019-05-13 22:09:43 JRebel: Monitoring Spring bean definitions in 'F:\vlis1\target\vlis-1.0-SNAPSHOT\WEB-INF\applicationContext.xml'. 2019-05-13 22:09:48 JRebel: Monitoring Spring bean definitions in 'F:\vlis1\target\vlis-1.0-SNAPSHOT\WEB-INF\cxf-servlet.xml'. 2019-05-13 22:09:48 JRebel: Monitoring Spring bean definitions in 'F:\vlis1\target\vlis-1.0-SNAPSHOT\WEB-INF\security.xml'. 2019-05-13 22:10:00 JRebel: Monitoring properties in 'file:/F:/vlis1/target/vlis-1.0-SNAPSHOT/WEB-INF/classes/jdbc.properties'. 2019-05-13 22:10:00 JRebel: Monitoring properties in 'file:/F:/vlis1/target/vlis-1.0-SNAPSHOT/WEB-INF/classes/mail.properties'. 2019-05-13 22:10:00 JRebel: Monitoring properties in 'file:/F:/vlis1/target/vlis-1.0-SNAPSHOT/WEB-INF/classes/hibernate.properties'. 2019-05-13 22:10:00 JRebel: Monitoring properties in 'file:/F:/vlis1/target/vlis-1.0-SNAPSHOT/WEB-INF/classes/package.properties'. **WARN [RMI TCP Connection(3)-127.0.0.1] SecurityInterceptor.afterPropertiesSet(141) | Could not validate configuration attributes as the SecurityMetadataSource did not return any attributes from getAllConfigAttributes()** 13-May-2019 22:42:01.737 INFO [RMI TCP Connection(3)-127.0.0.1] com.sun.faces.config.ConfigureListener.contextInitialized 初始化上下文 '/vlis1' 的 Mojarra 2.2.10 ( 20150205-0906 https://svn.java.net/svn/mojarra~svn/tags/2.2.10@14334) 13-May-2019 22:42:03.710 INFO [RMI TCP Connection(3)-127.0.0.1] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048:有 PostConstruct/PreDestroy 注释。标有这些注释的 ManagedBeans 方法将表示注释已处理。 13-May-2019 22:42:06.353 SEVERE [RMI TCP Connection(3)-127.0.0.1] com.sun.faces.config.JavaClassScanningAnnotationScanner$ConstantPoolInfo.containsAnnotation Unknow type constant pool 18 at position 32 ``` 看一下,我电脑4g内存启动时间半个小时,8g内存启动十几分钟, 启动时候mysql同时也在运行中, **WARN [RMI TCP Connection(3)-127.0.0.1] SecurityInterceptor.afterPropertiesSet(141) | Could not validate configuration attributes as the SecurityMetadataSource did not return any attributes from getAllConfigAttributes()** 这个在运行完之后就不动了,用的是jrebel debug启动
jboss eap 6.4 启动报错,,,jboss eap 6.4 启动报错
部署 deployment "angelPSRS.war" 包含 CDI 注解但未找到 beans.xml。 14:21:03,674 INFO [org.jboss.as.repository] (HttpManagementService-threads - 1) JBAS014900: 在位置 E:\jboss-eap-6.4\standalone\data\content\50\5e373bfaf16232c77dc8b7b6af5a8a30fe8ea2\content 上添加内容 14:21:03,754 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: 开始 "angelPSRS.war" 的部署(runtime-name: "angelPSRS.war") 14:21:10,312 WARN [org.jboss.as.ee] (MSC service thread 1-8) JBAS011006: 由于有异常抛出(请启用 DEBUG 日志级别以查看原因),没有安装可选组件 org.springframework.web.context.request.async.StandardServletAsyncWebRequest。 14:21:10,312 WARN [org.jboss.as.ee] (MSC service thread 1-8) JBAS011006: 由于有异常抛出(请启用 DEBUG 日志级别以查看原因),没有安装可选组件 org.springframework.http.server.ServletServerHttpAsyncRequestControl。 14:21:10,382 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010403: 部署兼容 JDBC 的驱动 class oracle.jdbc.OracleDriver (版本 11.1) 14:21:10,382 WARN [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016012: 部署 deployment "angelPSRS.war" 包含 CDI 注解但未找到 beans.xml。 14:21:10,422 INFO [org.jboss.web] (ServerService Thread Pool -- 72) JBAS018210: 注册 web 上下文 /angelPSRS 14:21:10,432 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/angelPSRS]] (ServerService Thread Pool -- 72) No Spring WebApplicationInitializer types detected on classpath 14:21:10,452 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/angelPSRS]] (ServerService Thread Pool -- 72) Initializing Spring root WebApplicationContext 14:21:12,842 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/angelPSRS]] (ServerService Thread Pool -- 72) JBWEB000287: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'channelController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.travelsky.angel.base.service.ChannelService com.travelsky.angel.base.controller.ChannelController.channelService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'channelService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.travelsky.angel.base.dao.ChannelDao com.travelsky.angel.base.service.impl.ChannelsServiceImpl.channelDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'channelDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.travelsky.angel.base.dao.impl.ChannelDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring-hibernate.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' defined in class path resource [spring-hibernate.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: java:jdbc/angelPSRS Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring-hibernate.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: java:jdbc/angelPSRS
如何让JPA查询不经过session。
JPA的查询会先从session上下文中获取对象,执行两次查询实际引用的对象是同一个。伪代码如下: ```Java Signature s = signatureRepository.findOne(id); s.setSignature(info); Object o = signatureRepository.getOne(id); (Signature) o).setSignature("test"); signatureRepository.save(s); ``` 这样存入数据库的是指是 **test** ,期望的值是存入 **info** 请问在不改变顺序的情况下,能让第二次查询为实时查询且不加载进session中?
SSH框架不能实现更新问题
先来spring配置 <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" default-autowire="byName" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 上下文注释配置 --> <context:annotation-config /> <context:component-scan base-package="com.ffour.yixing.entity" /> <!-- 引入项目配置属性文件 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- 数据库驱动类 --> <property name="driverClassName" value="${database.driverClassName}" /> <property name="url" value="${database.url}" /> <property name="username" value="${database.username}" /> <property name="password" value="${database.password}" /> </bean> <!-- 会话工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> </bean> <!-- 上下文组件扫描 --> <context:component-scan base-package="com.ffour.yixing"></context:component-scan> <!-- 定义事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" > <property name="dataSource" ref="dataSource"/> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="select*" propagation="REQUIRED" read-only="true" /> <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/> <!-- 其他方法使用默认的事务设置 --> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="interceptorPointCuts" expression="execution(* com.ffour.yixing.service.impl.*Impl.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" /> </aop:config> <bean id="sysUserInfoDao" class="com.ffour.yixing.dao.impl.SysUserInfoDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="sysUserInfoSV" class="com.ffour.yixing.service.impl.SysUserInfoImpl"> <property name="sysUserInfoDao" ref="sysUserInfoDao"></property> </bean> <bean id="sysStudentUserInfoDao" class="com.ffour.yixing.dao.impl.SysStudentUserInfoDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="sysStudentUserInfoSV" class="com.ffour.yixing.service.impl.SysStudentUserInfoImpl"> <property name="sysStudentUserInfoDao" ref="sysStudentUserInfoDao"></property> </bean> </beans>
报错javax.faces.context.ExceptionHandlerFactory
报错如下,工程在别的电脑上写的没问题,回家往mac里导就起不来了,百度了这些错误也没找到好的解决方法,发出来大家帮忙看看,勿喷。。。 ``` 一月 15, 2016 3:29:55 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Brawow' did not find a matching property. 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version: Apache Tomcat/8.0.26 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server built: Aug 18 2015 11:38:37 UTC 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server number: 8.0.26.0 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Name: Mac OS X 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Version: 10.11.2 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Architecture: x86_64 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java Home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Version: 1.7.0_79-b15 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Vendor: Oracle Corporation 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: /Users/lixiang/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: /Applications/apache-tomcat-8.0.26 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.base=/Users/lixiang/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.home=/Applications/apache-tomcat-8.0.26 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dwtp.deploy=/Users/lixiang/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.endorsed.dirs=/Applications/apache-tomcat-8.0.26/endorsed 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dfile.encoding=UTF-8 一月 15, 2016 3:29:55 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/lixiang/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. 一月 15, 2016 3:29:55 上午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-nio-8080"] 一月 15, 2016 3:29:55 上午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 一月 15, 2016 3:29:55 上午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-nio-8009"] 一月 15, 2016 3:29:55 上午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 一月 15, 2016 3:29:55 上午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 744 ms 一月 15, 2016 3:29:55 上午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Catalina 一月 15, 2016 3:29:55 上午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/8.0.26 一月 15, 2016 3:29:59 上午 org.apache.jasper.servlet.TldScanner scanJars 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 一月 15, 2016 3:29:59 上午 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 一月 15, 2016 3:29:59 上午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext INFO - Root WebApplicationContext: initialization started INFO - Refreshing Root WebApplicationContext: startup date [Fri Jan 15 03:29:59 CST 2016]; root of context hierarchy INFO - Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/applicationContext.xml] INFO - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7c0c89: defining beans [dataSource,sessionFactory,access_token,accessTokenService,accessTokenDao]; root of factory hierarchy INFO - HCANN000001: Hibernate Commons Annotations {4.0.1.Final} INFO - HHH000412: Hibernate Core {4.1.4.Final} INFO - HHH000206: hibernate.properties not found INFO - HHH000021: Bytecode provider name : javassist WARN - HHH000342: Could not obtain connection to query metadata : Access denied for user 'root'@'localhost' (using password: YES) INFO - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect INFO - HHH000422: Disabling contextual LOB creation as connection was null INFO - HHH000397: Using ASTQueryTranslatorFactory INFO - HHH000399: Using default transaction strategy (direct JDBC transactions) INFO - Root WebApplicationContext: initialization completed in 1262 ms 一月 15, 2016 3:30:00 上午 org.apache.catalina.core.ApplicationContext log 信息: Set web app root system property: 'webapp.root' = [/Users/lixiang/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Brawow/] 一月 15, 2016 3:30:00 上午 org.apache.catalina.core.ApplicationContext log 信息: Initializing log4j from [/Users/lixiang/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Brawow/WEB-INF/classes/log4j.properties] 一月 15, 2016 3:30:00 上午 com.sun.faces.config.ConfigureListener contextInitialized 信息: 初始化上下文 '/Brawow' 的 Mojarra 2.0.3 (FCS b03) 一月 15, 2016 3:30:01 上午 com.sun.faces.config.ConfigManager initialize 信息: Unsanitized stacktrace from failed start... java.lang.IllegalArgumentException: javax.faces.context.ExceptionHandlerFactory at javax.faces.FactoryFinder.validateFactoryName(FactoryFinder.java:650) at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:295) at com.sun.faces.config.processor.FactoryConfigProcessor.setFactory(FactoryConfigProcessor.java:279) at com.sun.faces.config.processor.FactoryConfigProcessor.processFactories(FactoryConfigProcessor.java:235) at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:189) at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:332) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:220) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) 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) 一月 15, 2016 3:30:01 上午 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! javax.faces.context.ExceptionHandlerFactory at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:351) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:220) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) 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) Caused by: java.lang.IllegalArgumentException: javax.faces.context.ExceptionHandlerFactory at javax.faces.FactoryFinder.validateFactoryName(FactoryFinder.java:650) at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:295) at com.sun.faces.config.processor.FactoryConfigProcessor.setFactory(FactoryConfigProcessor.java:279) at com.sun.faces.config.processor.FactoryConfigProcessor.processFactories(FactoryConfigProcessor.java:235) at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:189) at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:332) ... 10 more 一月 15, 2016 3:30:01 上午 org.apache.catalina.core.StandardContext startInternal 严重: One or more listeners failed to start. Full details will be found in the appropriate container log file 一月 15, 2016 3:30:01 上午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/Brawow] startup failed due to previous errors 一月 15, 2016 3:30:01 上午 com.sun.faces.config.ConfigureListener contextDestroyed 严重: Unexpected exception when attempting to tear down the Mojarra runtime java.lang.IllegalStateException: 启动时没有正确初始化应用程序,无法找到工厂:javax.faces.application.ApplicationFactory at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:263) at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:104) at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:312) at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4774) at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5390) at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) 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) 一月 15, 2016 3:30:01 上午 org.apache.catalina.core.ApplicationContext log 信息: Shutting down log4j 一月 15, 2016 3:30:01 上午 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.XmlWebApplicationContext). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 一月 15, 2016 3:30:01 上午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc 警告: The web application [Brawow] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 一月 15, 2016 3:30:01 上午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads 警告: The web application [Brawow] appears to have started a thread named [HouseKeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Thread.sleep(Native Method) org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:46) 一月 15, 2016 3:30:01 上午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads 警告: The web application [Brawow] appears to have started a thread named [Prototyper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Object.wait(Native Method) java.lang.Object.wait(Object.java:503) org.logicalcobwebs.proxool.PrototyperThread.doWait(PrototyperThread.java:69) org.logicalcobwebs.proxool.PrototyperThread.run(PrototyperThread.java:58) 一月 15, 2016 3:30:01 上午 org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks 严重: The web application [Brawow] created a ThreadLocal with key of type [com.sun.faces.util.Util$1] (value [com.sun.faces.util.Util$1@6ca75f0c]) and a value of type [java.util.HashMap] (value [{com.sun.faces.patternCache={ = }}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 一月 15, 2016 3:30:01 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 一月 15, 2016 3:30:01 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 一月 15, 2016 3:30:01 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 5448 ms ```
There is no Action mapped for namespace
使用的是J2EE+SHH框架, 具体代码如下: --- **struts.xml** ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="message" /> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- 指定Struts 2默认的ObjectFactory Bean - 交给Spring管理 --> <constant name="struts.objectFactory" value="spring" /> <!-- 开发者模式 --> <!-- <constant name="struts.devMode" value="true" /> --> <!-- 指定每次配置文件更改后,自动重新加载 --> <constant name="struts.configuration.xml.reload" value="false" /> </struts> ``` --- **applicationContext.xml** ``` **<?xml version="1.0" encoding="UTF-8"?> <!-- context是自动扫描和使用注解的上下文前缀;aop,tx是事物管理的前缀 -->** <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" default-autowire="byName"> <!-- 采用自动扫描的方式查找bean(DAO,Service等等),多个用逗号隔开 --> <context:component-scan base-package="com.cheer.bookshop" /> <!-- 定时器任务 --> <task:annotation-driven /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <description>配置数据源</description> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/bookstore?useUnicode=true&amp;characterEncoding=UTF-8"></property> <property name="username" value="root"></property> <property name="password" value="123456"></property> <!-- 初始化连接数量 --> <property name="initialSize" value="1"/> <!-- 最大活动连接数量,一般等于数据库的最大并发数 --> <property name="maxActive" value="100"/> <!-- 最大空闲(等待)连接数量 --> <property name="maxIdle" value="-1"/> <!-- 最小空闲(等待)连接数量 --> <property name="minIdle" value="0"/> <!-- 获取连接时等待时间,超出将抛异常,单位毫秒 --> <property name="maxWait" value="10000"/> </bean> <!-- 配置hibernate session工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <description>将数据源注入到sessionFactory,使用注解方式</description> <property name="dataSource" ref="dataSource"></property> <!-- 配置hibernate的一些属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.connection.release_mode">after_transaction</prop><!-- 释放session --> </props> </property> <!-- 自动扫描注解方式配置的hibernate映射文件(实体类) --> <property name="packagesToScan"> <list> <value>com.cheer.bookshop.Model</value> </list> </property> </bean> <!-- 定义事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <description> 增加事务管理</description> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 拦截器方式配置事务特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 给business配置事务管理 --> <aop:config proxy-target-class="true"> <aop:pointcut id="allManagerMethod" expression="execution (* com.cheer.bookshop.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" /> </aop:config> </beans> ``` --- **JSP页面登陆Form表单** ``` <s:form action="userlogin.action" method="post"> <p><font color="red">&nbsp;&nbsp;&nbsp;${msg}</font></p> <div class="form_row"> <label class="contact"><strong>Username:</strong></label> <input type="text" class="contact_input" name="user.username" value="${user.username}"/> </div> <div class="form_row"> <label class="contact"><strong>Password:</strong></label> <input type="password" class="contact_input" name="user.password" value="${user.password}"/> </div> <div class="form_row"> <div class="terms"> <input type="checkbox" name="terms" /> Remember me </div> </div> <div class="form_row"> <input type="submit" class="register" value="login" /> </div> </s:form> ``` --- **Action类** ``` package com.cheer.bookshop.action; import java.io.IOException; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import com.cheer.bookshop.Model.User; import com.cheer.bookshop.service.impl.UserServiceImpl; import com.opensymphony.xwork2.ActionSupport; @Namespace("/") public class UserAction extends ActionSupport { @Resource private UserServiceImpl userServiceImpl; private User user; private String msg; //用户登录 @Action(value = "userlogin", results = {@Result(name = "success", location = "/index.jsp"), @Result(name = "input", location = "/jsp/user/myaccount.jsp", type = "redirect") }) public String login(){ User userdb = userServiceImpl.login(user.getUsername()); if(userdb != null){ String password = user.getPassword(); if(password.equals(userdb.getPassword())){ user=userdb; return SUCCESS; }else{ msg="密码错误,请重新输入!"; return INPUT; } }else{ msg="用户名不存在,请注册!"; return INPUT; } } //用户注册 @Action(value = "userregister", results = {@Result(name = "success", location = "/jsp/user/myaccount.jsp", type = "redirect") }) public String register(){ userServiceImpl.register(user); return SUCCESS; } //验证用户名是否已经被使用 @Action(value = "validateUsername") public String validateUsername() throws IOException{ HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=UTF-8"); String username = request.getParameter("username"); boolean flag = userServiceImpl.validateUsername(username); if(flag){ response.getWriter().println("<p><font color='red'>用户名已经存在</font></p>"); }else{ response.getWriter().println("<p><font color='green'>用户名可以使用</font></p>"); } return NONE; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } } ``` --- 如上,Action有配置userlogin,登陆页form表单提交路径也是一样,单就是无法调整至aciton里,eclipse也没有报错,该如何解决? There is no Action mapped for namespace / and action name userlogin.
寻觅dwr调用方法缓慢的问题
<p>       前几天我遇到了一个问题,让我百思不得其解。我们项目需要用dwr开发,以前也用过,可是这次需要和Spring整合,很快一个下拉列表联动就做好了,可是进入Tomcat中运行相当慢,我在网上差了很多资料,但是都是一场空,下来看看我这个项目第一次写的代码。</p> <pre name="code" class="java">public class Deptement { private static SystemQuery systemQuery = null; private static TrainQuery trainQuery = null; Company company = new Company(); Department department = new Department(); public static void find(){ } // 调用公司方法 public Map ClassList() { // 得到spring上下文 ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] { "applicationContext-hibernate.xml" }); // 得到bean trainQuery = (TrainQuery)appContext.getBean("trainQueryTarget"); List companylist=new ArrayList(); Map reply = new HashMap(); // 调用bean方法 companylist=trainQuery.queryCompany(); System.out.println("+++++++++++"+companylist.size()); if(companylist.size()&gt;0){ for(int i=0;i&lt;companylist.size();i++){ company="(Company)" companylist.get(i);="" system.out.println("______"+company.getid().getcompanyid()+"______"+company.getid().getcompanyname());="" 循环将公司id与公司名称放入map="" reply.put(company.getid().getcompanyid(),company.getid().getcompanyname());="" }="" }="" system.out.println(reply.size());="" 返回map="" return="" reply;="" }="" 调用部门方法="" public="" map="" userlist(string="" classid){="" 得到spring上下文="" classpathxmlapplicationcontext="" appcontext="new" classpathxmlapplicationcontext(="" new="" string[]="" {="" "applicationcontext-hibernate.xml"="" });="" 得到bean="" systemquery="(SystemQuery)appContext.getBean(&amp;quot;systemQueryTarget&amp;quot;);" list="" deptementlist="new" arraylist();="" map="" reply="new" hashmap();="" 调用bean方法="" deptementlist="systemQuery.searchDepartmentList(Integer.parseInt(CLASSID));" system.out.println("+++++++++++"+deptementlist.size());="" if(deptementlist.size()=""&gt;0){ for(int i=0;i&lt;deptementlist.size();i++){ department="(Department)" deptementlist.get(i);="" system.out.println("______"+department.getid().getcompanyid()+"______"+department.getid().getdepartmentname());="" 循环将部门id和名称放入map="" reply.put(department.getid().getdepartmentid(),department.getid().getdepartmentname());="" }="" }="" system.out.println(reply.size());="" 返回map="" return="" reply;="" }="" }="" &lt;="" pre=""&gt; <p> </p> <p> </p> <p>这是后台方法,现在看看dwr文件</p> <pre name="code" class="xml">&lt;dwr&gt; &lt;allow&gt; &lt;create creator="new" javascript="Deptement"&gt; <param name="class" value="com.seavision.qjculture.common.Deptement" /> &lt;/create&gt; &lt;create creator="new" javascript="People"&gt; <param name="class" value="com.seavision.qjculture.common.People" /> &lt;/create&gt; &lt;/allow&gt; &lt;/dwr&gt; </pre> <p> </p> <p>web.xml就不用看了,大家应该比我更熟悉。 </p> <p>前台页面我也不写了,这次重点不是在展现,是解决为什么调用慢。</p> <p> </p> <p>    当这个功能完成后,我兴高采烈的将它部署到Tomcat下面,心想终于完了,开始运行,当我进入这个联动页面时,发现很久都没有响应,真不知道是怎么了,看看后台没有抛异常, 正郁闷的时候,突然页面出现了下拉列表的内容,大家可以想象得到这有多么长的时间才响应。这再交给客户,客户非跳起来不可,还什么ajax框架,比jsp响应还慢。</p> <p>直到下班我都没有解决,效率真低,第二天我又重新寻找问题,其实高手们一看就可以知道我写的方法有问题,大家可以看到,这虽然是与spring连用,但是并没有与spring的bean配合,这是一个问题,最大的问题是每次调用bean方法是都得到一次spring的上下文,这显然给服务器无形的压力。终于找到问题了。于是我把方法写到service层,重新配置dwr文件</p> <pre name="code" class="xml">&lt;dwr&gt; &lt;allow&gt; &lt;create creator="spring" javascript="Deptement"&gt; <param name="beanName" value="trainQueryTarget" /> &lt;/create&gt; &lt;create creator="spring" javascript="Company"&gt; <param name="beanName" value="systemQueryTarget" /> &lt;/create&gt; &lt;create creator="new" javascript="People"&gt; <param name="class" value="com.seavision.qjculture.common.People" /> &lt;/create&gt; &lt;/allow&gt; &lt;/dwr&gt; </pre> <p> </p> <p>再次运行,问题解决了。不知道你们遇见过这个问题吗?我要申请专利啦。呵呵!</p><br /><strong>问题补充</strong><br />放到src下最好</pre>
SSH框架应用的一个例子,不知道错在哪里,很郁闷
[b]开发环境:[/b] MyEclipse7+Tomcat5+MySQL5+Struts1.2+Hibernate3.2+Spring2.0 [b]相关代码:[/b] [color=indigo]index.jsp中代码:[/color] <body> <form action="addAdmin.do"> <input type="submit" value="OK" /> </form> </body> [color=indigo]AddAdmin.java代码:[/color] package edu.bhu.Kupid.actions; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import edu.bhu.Kupid.domain.Admins; import edu.bhu.Kupid.service.AdminsService; public class AddAdmin extends Action { private AdminsService admServer; public AdminsService getAdmServer() { return admServer; } public void setAdmServer(AdminsService admServer) { this.admServer = admServer; } public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ request.setCharacterEncoding("utf-8"); String loginname="admin"; String pwd="admin"; Admins adm=new Admins(); adm.setPwd(pwd); adm.setId("1234665"); adm.setLoginname(loginname); adm.setLevel(0); admServer.addAdmin(adm); return mapping.findForward("ok"); } } [color=indigo]AdminsService.java代码:[/color] package edu.bhu.Kupid.service; import java.util.List; import edu.bhu.Kupid.domain.Admins; public interface AdminsService { public void addAdmin(Admins adm); public List<Admins> findAdminsByName(String name); } [color=indigo]AdminsServiceImpl代码:[/color] package edu.bhu.Kupid.service; import java.util.List; import edu.bhu.Kupid.domain.Admins; import edu.bhu.Kupid.persist.AdminsDao; public class AdminsServiceImpl implements AdminsService { private AdminsDao admDao; public void addAdmin(Admins adm) { admDao.insert(adm); } public AdminsDao getAdmDao() { return admDao; } public void setAdmDao(AdminsDao admDao) { this.admDao = admDao; } public List<Admins> findAdminsByName(String name) { return null; } } [color=indigo]AdminsDao.java代码:[/color] package edu.bhu.Kupid.persist; import edu.bhu.Kupid.domain.Admins; public interface AdminsDao extends BaseDao<Admins,String>{ } [color=indigo]AdminsDaoImpl.java代码:[/color] package edu.bhu.Kupid.persist; import edu.bhu.Kupid.domain.Admins; import edu.bhu.Kupid.persist.BaseDaoImpl; public class AdminsDaoImpl extends BaseDaoImpl<Admins,String> implements AdminsDao { } [color=indigo]BaseDao.java代码:[/color] package edu.bhu.Kupid.persist; import java.io.Serializable; public interface BaseDao<T, PK extends Serializable> { public void insert(T entity); public void update(T entity); public void delete(T entity); public void deleteById(PK id); public T findById(PK id); } [color=indigo]BaseDaoImpl.java代码:[/color] package edu.bhu.Kupid.persist; import java.io.Serializable; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class BaseDaoImpl<T,PK extends Serializable> extends HibernateDaoSupport implements BaseDao<T, PK> { protected Class entityClass; public void delete(T entity) { getHibernateTemplate().delete(entity); } public void deleteById(PK id) { getHibernateTemplate().delete(getHibernateTemplate().get(entityClass, id)); } public T findById(PK id) { return (T)getHibernateTemplate().get(entityClass, id); } public void insert(T entity) { getHibernateTemplate().save(entity); } public void update(T entity) { getHibernateTemplate().update(entity); } } [color=indigo] Admins.java代码(这个BEAN的代码是利用MyEclipse的DBExplorer的Hibernate Reverse Engineering生成的)[/color] package edu.bhu.Kupid.domain; /** * Admins entity. @author MyEclipse Persistence Tools */ public class Admins implements java.io.Serializable { // Fields private String id; private String loginname; private String pwd; private Integer level; // Constructors /** default constructor */ public Admins() { } /** full constructor */ public Admins(String id, String loginname, String pwd, Integer level) { this.id = id; this.loginname = loginname; this.pwd = pwd; this.level = level; } // Property accessors public String getId() { return this.id; } public void setId(String id) { this.id = id; } public String getLoginname() { return this.loginname; } public void setLoginname(String loginname) { this.loginname = loginname; } public String getPwd() { return this.pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public Integer getLevel() { return this.level; } public void setLevel(Integer level) { this.level = level; } } [color=indigo]Admins.hbm.xml代码:[/color] <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="edu.bhu.Kupid.domain.Admins" table="admins" catalog="graduation"> <id name="id" type="java.lang.String"> <column name="id" length="128" /> <generator class="uuid.hex" /> </id> <property name="loginname" type="java.lang.String"> <column name="loginname" length="20" not-null="true" /> </property> <property name="pwd" type="java.lang.String"> <column name="pwd" length="20" not-null="true" /> </property> <property name="level" type="java.lang.Integer"> <column name="level" not-null="true" /> </property> </class> </hibernate-mapping> [color=indigo]spring-admins.xml代码:[/color] <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="adminsDao" class="edu.bhu.Kupid.persist.AdminsDaoImpl" parent="baseDao"> </bean> <bean id="adminsServer" class="edu.bhu.Kupid.service.AdminsServiceImpl"> <property name="admDao"> <ref bean="adminsDao"/> </property> </bean> <bean name="/addAdmin" class="edu.bhu.Kupid.actions.AddAdmin"> <property name="admServer"> <ref bean="adminsServer" /> </property> </bean> </beans> [color=indigo] applicationContext.xml代码:[/color] <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <import resource="spring-admins.xml" /> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/classes/configure.properties</value> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>${jdbc.driverClassName}</value> </property> <property name="url"> <value>${jdbc.url}</value> </property> <property name="username"> <value>${jdbc.username}</value> </property> <property name="password"> <value>${jdbc.password}</value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="mappingResources"> <list> <value>/edu/bhu/Kupid/domain/Admins.hbm.xml </value> <!-- 好多好多Hibernate --> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> ${hibernate.dialect} </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> </bean> <bean id="baseDao" class="edu.bhu.Kupid.persist.BaseDaoImpl" abstract="true"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> </beans> [color=indigo]struts-config.xml代码:[/color] <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans /> <global-exceptions /> <global-forwards /> <action-mappings > <action path="/addAdmin" type="edu.bhu.Kupid.actions.AddAdmin" validate="false" > <forward name="ok" path="/ok.jsp" ></forward> </action> </action-mappings> <message-resources parameter="edu.bhu.Kupid.resource.ApplicationResources" /> </struts-config> [color=indigo]web.xml代码:[/color] <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>SpringContextServlet</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <filter> <filter-name>OpenSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>OpenSessionInView</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> [b]程序目的:[/b] index.jsp上的按钮被点击后,一条Admin的信息入库。 [b] 产生错误:[/b] 浏览器中错误信息: HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) javax.servlet.http.HttpServlet.service(HttpServlet.java:689) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:173) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) root cause java.lang.NullPointerException edu.bhu.Kupid.actions.AddAdmin.execute(AddAdmin.java:37) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) javax.servlet.http.HttpServlet.service(HttpServlet.java:689) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:173) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs. Apache Tomcat/5.0.30 MyEclipse中错误信息: 无。 最后感谢您的帮助。祝您好运。棘手问题郁闷中。。。 [b]问题补充:[/b] AddAdmin第37行是:admServer.addAdmin(adm); [b]问题补充:[/b] 我说的嘛,怎么出空指针,昨天晚上做了这样一个试验: 注释掉原来37行的代码,然后手工创建spring上下文,就能通过。果然是SSH整合中有错误。 //admServer.addAdmin(adm); ApplicationContext ctx=new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"}); AdminsService admServer=(AdminsService)ctx.getBean("adminsServer"); admServer.addAdmin(adm); 我是第一次做SSH,不太会弄,请各位多指教。 现在还有一个很头疼的地方,就是struts,我用了tiles来做页面的分帧,于是给struts-config.xml文件加入了 <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" contentType="text/html; charset=UTF-8" /> <message-resources parameter="edu.bhu.Kupid.resource.ApplicationResources" /> <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-config.xml" /> </plug-in> 结果这段代码一加进来,jsp提交表单到action的时候就找不到action了,浏览器报404异常。 PS:回lewhwa :因为有一次我发项目,有个仁兄说下载太麻烦,不如直接贴代码的好,于是我就贴了代码。。。
一个SSH的系统错误
在启动tomcat时错误: <br /> <br />2008-11-7 17:38:18 org.apache.catalina.core.StandardContext start <br />严重: Error filterStart <br />2008-11-7 17:38:18 org.apache.catalina.core.StandardContext start <br />严重: Context [/exampleSSH] startup failed due to previous errors <br /> <br />谁能帮忙解决?  谢谢<br /><strong>问题补充:</strong><br />配置文件内容: <br /> <br />&lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" &lt;br=""&gt; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <br /> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; <br /> <br /> &lt;context-param&gt; <br /> &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; <br /> &lt;param-value&gt;/WEB-INF/application.xml&lt;/param-value&gt; <br /> &lt;/context-param&gt; <br /> <br /> &lt;servlet&gt; <br /> &lt;servlet-name&gt;SpringContextServlet&lt;/servlet-name&gt; <br /> &lt;servlet-class&gt; <br /> org.springframework.web.context.ContextLoaderServlet <br /> &lt;/servlet-class&gt; <br /> &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; <br /> &lt;/servlet&gt; <br /> &lt;filter&gt; <br /> &lt;filter-name&gt;struts2&lt;/filter-name&gt; <br /> &lt;filter-class&gt; <br /> org.apache.struts2.dispatcher.FilterDispatcher <br /> &lt;/filter-class&gt; <br /> &lt;/filter&gt; <br /> <br /> &lt;filter-mapping&gt; <br /> &lt;filter-name&gt;struts2&lt;/filter-name&gt; <br /> &lt;url-pattern&gt;/*&lt;/url-pattern&gt; <br /> &lt;/filter-mapping&gt; <br /> <br /> &lt;welcome-file-list&gt; <br /> &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; <br /> &lt;/welcome-file-list&gt; <br />&lt;/web-app&gt; <br /><br /><strong>问题补充:</strong><br />下面是控制台打印出来的全部信息: <br />2008-11-7 21:35:03 org.apache.catalina.core.AprLifecycleListener lifecycleEvent <br />信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\eclipse3.2\eclipse321\bin;D:\eclipse3.2\tomcat\Tomcat 5.5\bin <br />2008-11-7 21:35:04 org.apache.coyote.http11.Http11BaseProtocol init <br />信息: Initializing Coyote HTTP/1.1 on http-8080 <br />2008-11-7 21:35:04 org.apache.catalina.startup.Catalina load <br />信息: Initialization processed in 4359 ms <br />2008-11-7 21:35:05 org.apache.catalina.core.StandardService start <br />信息: Starting service Catalina <br />2008-11-7 21:35:05 org.apache.catalina.core.StandardEngine start <br />信息: Starting Servlet Engine: Apache Tomcat/5.5.15 <br />2008-11-7 21:35:05 org.apache.catalina.core.StandardHost start <br />信息: XML validation disabled <br />log4j:WARN No appenders could be found for logger (org.apache.catalina.session.ManagerBase). <br />log4j:WARN Please initialize the log4j system properly. <br />2008-11-7 21:35:10 org.apache.catalina.core.StandardContext start <br />严重: Error filterStart <br />2008-11-7 21:35:10 org.apache.catalina.core.StandardContext start <br />严重: Context [/exampleSSH] startup failed due to previous errors <br />2008-11-7 21:35:11 org.apache.coyote.http11.Http11BaseProtocol start <br />信息: Starting Coyote HTTP/1.1 on http-8080 <br />2008-11-7 21:35:12 org.apache.jk.common.ChannelSocket init <br />信息: JK: ajp13 listening on /0.0.0.0:8009 <br />2008-11-7 21:35:12 org.apache.jk.server.JkMain start <br />信息: Jk running ID=0 time=0/532  config=null <br />2008-11-7 21:35:13 org.apache.catalina.storeconfig.StoreLoader load <br />信息: Find registry server-registry.xml at classpath resource <br />2008-11-7 21:35:13 org.apache.catalina.startup.Catalina start <br />信息: Server startup in 9125 ms <br />2008-11-7 21:35:51 org.apache.catalina.startup.HostConfig checkResources <br />信息: Reloading context [/exampleSSH] <br />2008-11-7 21:35:51 org.apache.catalina.core.StandardContext stop <br />信息: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/exampleSSH] has not been started <br />log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider). <br />log4j:WARN Please initialize the log4j system properly. <br />2008-11-7 21:35:53 org.apache.catalina.core.StandardContext start <br />严重: Error filterStart <br />2008-11-7 21:35:53 org.apache.catalina.core.StandardContext start <br />严重: Context [/exampleSSH] startup failed due to previous errors<br /><strong>问题补充:</strong><br />补充一点:使用Spring上下文启动监听器 就会报错error LisenerStart<br /><strong>问题补充:</strong><br />导入的spring包会导致哪些错误?<br /><strong>问题补充:</strong><br />我觉得代码上因该是没有问题的,spring配置放在了WEB-INF下 这个因该不会是错误根源吧 <br /> <br />会不会是导入的包发生了冲突,或者是其他的配置上的错误呢?<br /><strong>问题补充:</strong><br />我用的是jdk1.5  平时用的包都用上了...<br /><strong>问题补充:</strong><br />导入的包有: <br />commons-dbcp.jar <br />commons-logging-1.0.4.jar <br />ommaons-pool-1.3.jar <br />freemarker-2.3.8.jar <br />hibernate3.jar <br />log4j.jar <br />msbase.jar <br />mssqlserver.jar <br />mstil.jar <br />spring.jar <br />standard.jar <br />struts2-core-2.0.11.jar <br />struts2-spring-plugin-2.0.11.jar <br />struts.jar <br />xwork-2.0.4.jar<br /><strong>问题补充:</strong><br />cats_tiger 谢谢你的再三帮助 我用了你提供的web.xml文件 <br />不过可惜 问题还是没有解决<br /><strong>问题补充:</strong><br />asm,cglib,dom4j,spring-aspects.jar,antlr、aspectjrt.jar、aspectjweaver.jar,jta,activation...这些包刚才我全加了 可还是.... <br /> <br />sui366@163.com 这是我的邮箱 麻烦哪位大哥发个SSH的例子给我 谢谢了!<br /><strong>问题补充:</strong><br />呵呵  你告诉我要加哪些包  比如截张图片 一起发   谢谢 了 <br />万望你好人做到底  真的谢谢了  这个问题我已经弄了两天半了  谢谢
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
阿里P8数据架构师:顶级开发者都在用什么数据库?
其实从去年已经隐隐约约感觉到数据库的有变化,只是没有想到变得这么快。今年的一些事情实实在在地给了某些数据库重击,如果以前去某数据库还是喊喊,然后该用还用,今年从传统领域刮起的去某数据库的风,已经开始了,并且后面的乌云密布也看得见。 最近看一篇国外的开源产品提供厂商的一篇文字,主要是在询问了他的几百位客户后得出了下图中的2019年数据库的使用趋势。 从图中可以看出,MySQL以38.9...
面试官:关于Java性能优化,你有什么技巧
通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。 一般有两种方案:即优化代码或更改设计方法。我们一般会选择后者,因为不去调用以下代码要比调用一些优化的代码更能提高程序的性能。而一个设计良好的程序能够精简代码,从而提高性能。 下面将提供一些在JAVA程序的设计和编码中,为了能够提高JAVA程序的性能,而经常采用的一些方法和技巧。 1.对象的生成和大小的调整。 J...
互联网公司分布式系统架构演进之路
介绍 分布式和集群的概念经常被搞混,现在一句话让你明白两者的区别。 分布式:一个业务拆分成多个子业务,部署在不同的服务器上 集群:同一个业务,部署在多个服务器上 例如:电商系统可以拆分成商品,订单,用户等子系统。这就是分布式,而为了应对并发,同时部署好几个用户系统,这就是集群 1 单应用架构 2 应用服务器和数据库服务器分离 单机负载越来越来,所以要将应用服务器和数据库服务器分离 3 应用服务...
【图解算法面试】记一次面试:说说游戏中的敏感词过滤是如何实现的?
版权声明:本文为苦逼的码农原创。未经同意禁止任何形式转载,特别是那些复制粘贴到别的平台的,否则,必定追究。欢迎大家多多转发,谢谢。 小秋今天去面试了,面试官问了一个与敏感词过滤算法相关的问题,然而小秋对敏感词过滤算法一点也没听说过。于是,有了下下事情的发生… 面试官开怼 面试官:玩过王者荣耀吧?了解过敏感词过滤吗?,例如在游戏里,如果我们发送“你在干嘛?麻痹演员啊你?”,由于“麻痹”是一个敏感词,...
程序员需要了解的硬核知识之汇编语言(一)
之前的系列文章从 CPU 和内存方面简单介绍了一下汇编语言,但是还没有系统的了解一下汇编语言,汇编语言作为第二代计算机语言,会用一些容易理解和记忆的字母,单词来代替一个特定的指令,作为高级编程语言的基础,有必要系统的了解一下汇编语言,那么本篇文章希望大家跟我一起来了解一下汇编语言。 汇编语言和本地代码 我们在之前的文章中探讨过,计算机 CPU 只能运行本地代码(机器语言)程序,用 C 语言等高级语...
OpenCV-Python 绘图功能 | 七
目标 学习使用OpenCV绘制不同的几何形状 您将学习以下功能:cv.line(),cv.circle(),cv.rectangle(),cv.ellipse(),cv.putText()等。 代码 在上述所有功能中,您将看到一些常见的参数,如下所示: img:您要绘制形状的图像 color:形状的颜色。对于BGR,将其作为元组传递,例如:(255,0,0)对于蓝色。对于灰度,只需传递...
GitHub 标星 1.6w+,我发现了一个宝藏项目,作为编程新手有福了!
大家好,我是 Rocky0429,一个最近老在 GitHub 上闲逛的蒟蒻… 特别惭愧的是,虽然我很早就知道 GitHub,但是学会逛 GitHub 的时间特别晚。当时一方面是因为菜,看着这种全是英文的东西难受,不知道该怎么去玩,另一方面是一直在搞 ACM,没有做一些工程类的项目,所以想当然的以为和 GitHub 也没什么关系(当然这种想法是错误的)。 后来自己花了一个星期看完了 Pyt...
Java知识体系最强总结(2020版)
更新于2019-12-15 10:38:00 本人从事Java开发已多年,平时有记录问题解决方案和总结知识点的习惯,整理了一些有关Java的知识体系,这不是最终版,会不定期的更新。也算是记录自己在从事编程工作的成长足迹,通过博客可以促进博主与阅读者的共同进步,结交更多志同道合的朋友。特此分享给大家,本人见识有限,写的博客难免有错误或者疏忽的地方,还望各位大佬指点,在此表示感激不尽。 文章目录...
计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
介绍几个可以下载编程电子书籍的网站。 1.Github Github上编程书资源很多,你可以根据类型和语言去搜索。推荐几个热门的: free-programming-books-zh_CN:58K 星的GitHub,编程语言、WEB、函数、大数据、操作系统、在线课程、数据库相关书籍应有尽有,共有几百本。 Go语言高级编程:涵盖CGO,Go汇编语言,RPC实现,Protobuf插件实现,Web框架实...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Fiddler+夜神模拟器进行APP抓包
Fiddler+夜神模拟器进行APP抓包 作者:霞落满天 需求:对公司APP进行抓包获取详细的接口信息,这是现在开发必备的。 工具:Fiddler抓包,夜神模拟器 模拟手机 安装APP 1.下载Fiddler https://www.telerik.com/download/fiddler Fiddler正是在这里帮助您记录计算机和Internet之间传递的所有HTTP和HTTPS通信...
小白学 Python 爬虫(42):春节去哪里玩(系列终篇)
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Linux基础入门 小白学 Python 爬虫(4):前置准备(三)Docker基础入门 小白学 Python 爬虫(5):前置准备(四)数据库基础 小白学 Python 爬虫(6):前置准备(...
一文带你看清 HTTP 所有概念
上一篇文章我们大致讲解了一下 HTTP 的基本特征和使用,大家反响很不错,那么本篇文章我们就来深究一下 HTTP 的特性。我们接着上篇文章没有说完的 HTTP 标头继续来介绍(此篇文章会介绍所有标头的概念,但没有深入底层) HTTP 标头 先来回顾一下 HTTP1.1 标头都有哪几种 HTTP 1.1 的标头主要分为四种,通用标头、实体标头、请求标头、响应标头,现在我们来对这几种标头进行介绍 通用...
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东...
破14亿,Python分析我国存在哪些人口危机!
一、背景 二、爬取数据 三、数据分析 1、总人口 2、男女人口比例 3、人口城镇化 4、人口增长率 5、人口老化(抚养比) 6、各省人口 7、世界人口 四、遇到的问题 遇到的问题 1、数据分页,需要获取从1949-2018年数据,观察到有近20年参数:LAST20,由此推测获取近70年的参数可设置为:LAST70 2、2019年数据没有放上去,可以手动添加上去 3、将数据进行 行列转换 4、列名...
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ...... ...
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
[数据结构与算法] 排序算法之归并排序与基数排序
归并排序 归并排序(MERGE-SORT)是利用归并的思想实现的排序方法,该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divide)成一些小的问题然后递归求解,而治(conquer)的阶段则将分的阶段得到的各答案"修补"在一起,即分而治之)。 基本思想 可以看到这种结构很像一棵完全二叉树,本文的归并排序我们采用递归去实现(也可采用迭代的方式去实现)。分阶段可以...
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合...
史上最牛逼的 Eclipse 快捷键,提高开发效率!
如果你在使用IDEA,请参考博主另外的一篇idea快捷键的博客。
如何快速打好Java基础?
二哥,我是一名大学生,专业是电力工程,但想自学 Java,如何快速打好基础呢? 微信上 tison 向我提出了这个问题。我想我是有资格来回答的,从北京奥运会那年开始学 Java,到现在已经有 10 多个年头了,真的是从一名编程白痴一步步走到现在的。 我在各大技术网站上分享了不少 Java 方面的原创文章,不知道影响了多少初学者,反正文章的留言中经常能看到他们由衷的感谢。现在每天仍然有不少同学(...
在三线城市工作爽吗?
我是一名程序员,从正值青春年华的 24 岁回到三线城市洛阳工作,至今已经 6 年有余。一不小心又暴露了自己的实际年龄,但老读者都知道,我驻颜有术,上次去看房子,业务员肯定地说:“小哥肯定比我小,我今年还不到 24。”我只好强颜欢笑:“你说得对。” 从我拥有记忆到现在进入而立之年,我觉得,我做过最明智的选择有下面三个: 1)高中三年,和一位女同学保持着算不上朋友的冷淡关系;大学半年,把这位女同学追到...
相关热词 c# singleton c#中类的默认值是 c#各种进制之间的转换 c# 正则表达式保留汉字 c#后台跨域 c#基础代码大全 c#指定combox选择 c#关系 mono c# 相差毫秒 用c#做一个简易计算器
立即提问