jublikon
jublikon

Reputation: 3447

Spring - project not running but no error

I have a spring project followed by that tutorial.

Problem: The server starts with the application and does not give any error message. The application does not seem to crash, too. Unfortunately I have the guess that it is not really running.

console output:

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\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\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

It should do some database operation but the database is empty after running the code.

I am not able to debug because Spring Tool Suite does not stop at the breaktpoint.

The only thing I see after running is a 404 message in the browser.

Question: Why does spring not run its main application class?

application 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 configuration file

<?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>

Upvotes: 1

Views: 2206

Answers (1)

Roman C
Roman C

Reputation: 1

The example from the tutorial is a Java Project (not a Dynamic Web one). Thus it should be configured in Eclipse that will use Java launcher to run your application standalone from the command line, i.e. without any web server involved like Tomcat, etc.

Upvotes: 2

Related Questions