A simple blog created during Java/OOP course in university.

Username/password auth, admin can add/edit/delete blog posts, users (after registration) can add comments, vote (+1/-1) for posts and comments.

Can be useful for someone who is learning the techonologies/frameworks used here.

Features:

Installation

Requirements:

#

  1. Obtain the project source files (git clone or download and extract zip archive).

  2. Modify configuration if needed.

    Spring profiles are used to apply different configuration files for development (dev), real server (prod) and tests (test).

    • uploading-<profile>.properties files (in src\main\resources directory) contain directory path for user uploaded files (such as avatar images).

    Example (uploading-prod.properties):

    uploading.dirpath=/var/blog/upload/
    • datasource-<profile>.xml files (in src\main\resources directory) contain database configuration: database driver, address, name, username/password, ...
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/blog" />
        <property name="username" value="BlogDbUser" />
        <property name="password" value="BlogDbPassword" />
        ...
           <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
           ...

    The database must contain schema with the specified name (blog by default) and user with the specified name/password.

    If you want to use another database instead of MySQL you will need to modify driverClassName, url and hibernate.dialect values (highlighted above) and supply the JDBC driver (such as by adding Maven dependency to pom.xml).

    This line specifies SQL files that will be executed when database is created (by default it fills database with some demo data and creates a table for Spring Security “remember me” feature)

    <entry key="hibernate.hbm2ddl.import_files" value="/security-tables.sql,/dummy-data.sql" />

    Also note this line:

    <entry key="hibernate.hbm2ddl.auto" value="create"/>

    It will drop and create database tables each time you deploy the project.

    See Hibernate, JDBC and Spring documentation for more information about possible configuration parameters.

    By default the same datasource-dev.xml file is used for both dev and prod profiles. If needed, you can create a separate file (datasource-prod.xml) and modify <beans profile="prod"> node in database.xml to use it:

    <beans profile="prod">
        <import resource="classpath:/datasource-prod.xml"/>
    </beans>
  3. Run Maven verify goal. This will download all dependencies, run JUnit tests and build WAR file. Check Maven output to see if all tests and build are completed successfully.

  4. Set -Dspring.profiles.active system property to specify profile that will be used. If not set the default profile is dev.

    For example in <tomcat_dir>/bin/setenv.sh:

    JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=prod"
  5. Deploy the WAR file to Tomcat (or other web server).

  6. Go to http://your-server-address/blog (if deployed with default Tomcat settings) to see if it is working.