Spring - 项目不是 运行 但没有错误
Spring - project not running but no error
我有一个 spring 项目,然后是那个 tutorial。
问题:服务器启动应用程序,不给出任何错误信息。该应用程序似乎也没有崩溃。不幸的是,我猜测它并不是真正的 运行ning。
控制台输出:
Jun 24, 2016 1:39:36 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringDataDemo' did not find a matching property.
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version: Apache Tomcat/8.0.36
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built: Jun 9 2016 13:55:50 UTC
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number: 8.0.36.0
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name: Windows 10
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version: 10.0
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture: amd64
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home: C:\Program Files\Java\jre1.8.0_91
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version: 1.8.0_91-b14
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor: Oracle Corporation
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE: C:\Users\user\Development\Spring\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME: C:\Users\user\Development\Spring\Server\apache-tomcat-8.0.36
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=C:\Users\muser\Development\Spring\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=C:\Users\user\Development\Spring\Server\apache-tomcat-8.0.36
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=C:\Users\user\Development\Spring\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=C:\Users\user\Development\Spring\Server\apache-tomcat-8.0.36\endorsed
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=Cp1252
Jun 24, 2016 1:39:36 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_91\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_91/bin/server;C:/Program Files/Java/jre1.8.0_91/bin;C:/Program Files/Java/jre1.8.0_91/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\xampp\php;C:\Program Files\nodejs;C:\ProgramData\ComposerSetup\bin;C:\Users\dennis.goldenberg\AppData\Roaming\npm;C:\Users\dennis.goldenberg\AppData\Roaming\Composer\vendor\bin;C:\Users\dennis.goldenberg\AppData\Roaming\npm\node_modules\gulp\bin;C:\Program Files\Java\jdk1.8.0_91\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\GitExtensions\;C:\Users\user\Development\Spring\eclipse-jee-mars-2-win32-x86_64\eclipse;C:\Program Files\Apache\maven\bin;C:\Program Files\Apache\maven\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server0\DTS\Binn\;C:\Users\user\AppData\Local\Android\Sdk\platform-tools;C:\Users\user\Development\Spring\sts-bundle\sts-3.7.3.RELEASE;;.
Jun 24, 2016 1:39:36 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Jun 24, 2016 1:39:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Jun 24, 2016 1:39:36 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Jun 24, 2016 1:39:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 434 ms
Jun 24, 2016 1:39:36 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service Catalina
Jun 24, 2016 1:39:36 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.0.36
Jun 24, 2016 1:39:38 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: 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.
Jun 24, 2016 1:39:38 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
Jun 24, 2016 1:39:38 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
Jun 24, 2016 1:39:38 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 1274 ms
它应该做一些数据库操作,但是在 运行 代码之后数据库是空的。
我无法调试,因为 Spring Tool Suite
没有在断点处停止。
我在 运行ning 之后唯一看到的是浏览器中的一条 404
消息。
问题:为什么spring不是运行它的主要应用程序class?
申请class:
public class SpringDataDemo {
public static void main(String[] args) {
try {
ApplicationContext context = new ClassPathXmlApplicationContext("resources\spring-configuration.xml");
// Fetch the DAO from Spring Bean Factory
EmployeeDao employeeDao = (EmployeeDao) context.getBean("EmployeeDaoImpl");
Employee employee = new Employee("Employee123");
// employee.setEmployeeId("1");
// Save an employee Object using the configured Data source
employeeDao.save(employee);
System.out.println("Employee Saved with EmployeeId " + employee.getEmployeeId());
// find an object using Primary Key
Employee emp = employeeDao.findByPrimaryKey(employee.getEmployeeId());
System.out.println(emp);
// Close the ApplicationContext
((ConfigurableApplicationContext) context).close();
} catch (BeansException | SQLException e) {
e.printStackTrace();
}
}
}
spring 配置文件
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" 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/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.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.base" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/maschinedb?serverTimezone=UTC" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="jcgPersistence" />
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="META-INF/persistence.xml" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
</beans>
教程中的示例是一个 Java 项目(不是动态 Web 项目)。因此,它应该在 Eclipse 中配置,它将使用 Java 启动器从命令行独立地 运行 您的应用程序,即不涉及任何 Web 服务器,如 Tomcat 等
我有一个 spring 项目,然后是那个 tutorial。
问题:服务器启动应用程序,不给出任何错误信息。该应用程序似乎也没有崩溃。不幸的是,我猜测它并不是真正的 运行ning。
控制台输出:
Jun 24, 2016 1:39:36 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringDataDemo' did not find a matching property.
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version: Apache Tomcat/8.0.36
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built: Jun 9 2016 13:55:50 UTC
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number: 8.0.36.0
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name: Windows 10
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version: 10.0
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture: amd64
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home: C:\Program Files\Java\jre1.8.0_91
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version: 1.8.0_91-b14
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor: Oracle Corporation
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE: C:\Users\user\Development\Spring\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME: C:\Users\user\Development\Spring\Server\apache-tomcat-8.0.36
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=C:\Users\muser\Development\Spring\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=C:\Users\user\Development\Spring\Server\apache-tomcat-8.0.36
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=C:\Users\user\Development\Spring\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=C:\Users\user\Development\Spring\Server\apache-tomcat-8.0.36\endorsed
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=Cp1252
Jun 24, 2016 1:39:36 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_91\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_91/bin/server;C:/Program Files/Java/jre1.8.0_91/bin;C:/Program Files/Java/jre1.8.0_91/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\xampp\php;C:\Program Files\nodejs;C:\ProgramData\ComposerSetup\bin;C:\Users\dennis.goldenberg\AppData\Roaming\npm;C:\Users\dennis.goldenberg\AppData\Roaming\Composer\vendor\bin;C:\Users\dennis.goldenberg\AppData\Roaming\npm\node_modules\gulp\bin;C:\Program Files\Java\jdk1.8.0_91\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\GitExtensions\;C:\Users\user\Development\Spring\eclipse-jee-mars-2-win32-x86_64\eclipse;C:\Program Files\Apache\maven\bin;C:\Program Files\Apache\maven\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server0\DTS\Binn\;C:\Users\user\AppData\Local\Android\Sdk\platform-tools;C:\Users\user\Development\Spring\sts-bundle\sts-3.7.3.RELEASE;;.
Jun 24, 2016 1:39:36 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Jun 24, 2016 1:39:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Jun 24, 2016 1:39:36 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Jun 24, 2016 1:39:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Jun 24, 2016 1:39:36 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 434 ms
Jun 24, 2016 1:39:36 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service Catalina
Jun 24, 2016 1:39:36 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.0.36
Jun 24, 2016 1:39:38 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: 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.
Jun 24, 2016 1:39:38 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
Jun 24, 2016 1:39:38 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
Jun 24, 2016 1:39:38 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 1274 ms
它应该做一些数据库操作,但是在 运行 代码之后数据库是空的。
我无法调试,因为 Spring Tool Suite
没有在断点处停止。
我在 运行ning 之后唯一看到的是浏览器中的一条 404
消息。
问题:为什么spring不是运行它的主要应用程序class?
申请class:
public class SpringDataDemo {
public static void main(String[] args) {
try {
ApplicationContext context = new ClassPathXmlApplicationContext("resources\spring-configuration.xml");
// Fetch the DAO from Spring Bean Factory
EmployeeDao employeeDao = (EmployeeDao) context.getBean("EmployeeDaoImpl");
Employee employee = new Employee("Employee123");
// employee.setEmployeeId("1");
// Save an employee Object using the configured Data source
employeeDao.save(employee);
System.out.println("Employee Saved with EmployeeId " + employee.getEmployeeId());
// find an object using Primary Key
Employee emp = employeeDao.findByPrimaryKey(employee.getEmployeeId());
System.out.println(emp);
// Close the ApplicationContext
((ConfigurableApplicationContext) context).close();
} catch (BeansException | SQLException e) {
e.printStackTrace();
}
}
}
spring 配置文件
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" 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/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.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.base" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/maschinedb?serverTimezone=UTC" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="jcgPersistence" />
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="META-INF/persistence.xml" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
</beans>
教程中的示例是一个 Java 项目(不是动态 Web 项目)。因此,它应该在 Eclipse 中配置,它将使用 Java 启动器从命令行独立地 运行 您的应用程序,即不涉及任何 Web 服务器,如 Tomcat 等