我有点迷失这个事实:
show status like 'con%';
+-----------------------------------+-------+
| Variable_name | Value |
+-----------------------------------+-------+
| Connection_errors_accept | 0 |
| Connection_errors_internal | 0 |
| Connection_errors_max_connections | 0 |
| Connection_errors_peer_address | 0 |
| Connection_errors_select | 0 |
| Connection_errors_tcpwrap | 0 |
| Connections | 10535 |
+-----------------------------------+-------+
Run Code Online (Sandbox Code Playgroud)
我在这里读了一些类似的问题,但那些不是我的问题,所以我在这里.
我使用MySQL和Hibernate.在我的webapp中,有一个静态的HibernateUtil类来访问数据库:
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final Logger log = Logger.getLogger(HibernateUtil.class);
private static SessionFactory sessionFactory;
static {
try …Run Code Online (Sandbox Code Playgroud) 我知道有很多类似的问题.我看了很多,但问题仍然存在.
我有一个已创建但未自动装配的服务.在项目和测试中都没有(!)手动启动(就像在这个问题中一样)
Tomcat输出说,这两个bean都被发现并创建.至少第一项服务不会注入应有的位置.我不知道第二个.
服务(接口):
public interface SchoolService {
public School getSchool(String id);
}
Run Code Online (Sandbox Code Playgroud)
服务(实施):
@Service
@Transactional
public class SchoolServiceImpl implements SchoolService {
@Autowired
private SchoolDAO schoolDAO;
public School getSchool(String id) {
//database things
return school;
}
}
Run Code Online (Sandbox Code Playgroud)
它被"召唤"的地方
public class SchoolMenu implements Serializable {
@Autowired
private SchoolService schoolService;
public SchoolMenu () {
//here schoolService is null
School school = schoolService.getSchool("id");
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序的context.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:p="http://www.springframework.org/schema/p"
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-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx …Run Code Online (Sandbox Code Playgroud)